Revision: 34462
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 22, 2010 21:24 by jonjoneshomegmailcom
Initial Code
/// <summary>
/// Gets the current category and stage.
/// </summary>
public bool GetCurrentCategoryAndStage(
out Category category,
out Stage stage)
{
category = null;
stage = null;
var result = Request.QueryString[WebConstants.CatagoryNavigatorQueryStringKey];
// When no options are specified use the defaults
// which are the first category and first stage
if (String.IsNullOrEmpty(result))
{
category = (ReferenceData.Categories != null && ReferenceData.Categories.Length > 0)
? ReferenceData.Categories[0] : null;
stage = (category != null && category.Stages != null && category.Stages.Length > 0)
? category.Stages[0] : null;
// Success when all values have been set
return category != null && stage != null;
}
var options = result.Split(new[] { WebConstants.CategoryNavigatorSeparator }, StringSplitOptions.RemoveEmptyEntries);
// Format of querystring value should be {0}:{1} or to be more accurate
// {0}[Separator]{1}
if (options.Length < 2)
return false;
// Here are the Id in hash form
int categoryIdQueryStringEntry;
int stageIdQueryStringEntry;
if (!int.TryParse(options[0], out categoryIdQueryStringEntry) || !int.TryParse(options[1], out stageIdQueryStringEntry))
return false;
// Now there are all the required elements to get
// the category and stage its time to return them
// to the client
category = ReferenceData.Categories
.Where(x => ConvertToQueryStringEntry(x.Id) == categoryIdQueryStringEntry)
.FirstOrDefault();
if (category == null)
return false;
stage = category.Stages
.Where(x => ConvertToQueryStringEntry(x.Id) == stageIdQueryStringEntry)
.FirstOrDefault();
if(stage == null)
return false;
return true;
}out on a method
Initial URL
Initial Description
Initial Title
out on a method
Initial Tags
Initial Language
C#