public ActionResult Index(string categoryUrlName, int hideRecordsWithoutVideo = 0) { var category = CategoryService.GetCategoryByUrlName(categoryUrlName); if (category == null) { return(new HttpNotFoundResult()); } var categoryModel = CategoryService.GetCategoryModel(category.Id); var viewModel = CreateViewModel <LeaderboardPageViewModel>(); viewModel.Category = categoryModel; viewModel.HideRecordsWithoutVideo = hideRecordsWithoutVideo == 1; if (category.Parent != null) { viewModel.SectionHeading = category.Parent.Section.Name; viewModel.Heading = category.Parent.Name; viewModel.SiblingCategories = category.Parent.Subcategories .Select(c => CategoryService.GetCategoryModel(c.Id)).ToArray();; } else { viewModel.SectionHeading = category.Section.Name; viewModel.Heading = category.Name; } IEnumerable <Record> records = _leaderboardService.GetRecords(category.Id, viewModel.HideRecordsWithoutVideo); IEnumerable <RankedRecord> rankedRecords; if (category.GameTime && category.RealTime) { records = records.OrderBy(r => r.GameTimeSeconds).ThenBy(r => r.RealTimeSeconds).ThenBy(r => r.DateSubmitted); rankedRecords = RankRecords(records, r => $"{r.GameTimeSeconds}|{r.RealTimeSeconds}"); } else if (category.GameTime) { records = records.OrderBy(r => r.GameTimeSeconds).ThenBy(r => r.DateSubmitted); rankedRecords = RankRecords(records, r => r.GameTimeSeconds); } else if (category.EscapeGameTime) { records = records.OrderByDescending(r => r.CeresTime).ThenBy(r => r.DateSubmitted); rankedRecords = RankRecords(records, r => r.CeresTime); } else { records = records.OrderBy(r => r.RealTimeSeconds).ThenBy(r => r.DateSubmitted); rankedRecords = RankRecords(records, r => r.RealTimeSeconds); } viewModel.Records = rankedRecords .Select(r => MapRecord(r, category)) .ToArray(); return(View(viewModel)); }
public ActionResult Index(string categoryUrlName) { var category = CategoryService.GetCategoryByUrlName(categoryUrlName); if (category == null) { return(new HttpNotFoundResult()); } var categoryModel = CategoryService.GetCategoryModel(category.Id); var viewModel = CreateViewModel <LeaderboardPageViewModel>(); viewModel.Category = categoryModel; if (category.Parent != null) { viewModel.SectionHeading = category.Parent.Section.Name; viewModel.Heading = category.Parent.Name; viewModel.SiblingCategories = category.Parent.Subcategories .Select(c => CategoryService.GetCategoryModel(c.Id)).ToArray();; } else { viewModel.SectionHeading = category.Section.Name; viewModel.Heading = category.Name; } IEnumerable <Record> records = _leaderboardService.GetRecords(category.Id); if (category.GameTime && category.RealTime) { records = records.OrderBy(r => r.GameTimeSeconds).ThenBy(r => r.RealTimeSeconds).ThenBy(r => r.DateSubmitted); } else if (category.GameTime) { records = records.OrderBy(r => r.GameTimeSeconds).ThenBy(r => r.DateSubmitted); } else if (category.EscapeGameTime) { records = records.OrderByDescending(r => r.CeresTime).ThenBy(r => r.DateSubmitted); } else { records = records.OrderBy(r => r.RealTimeSeconds).ThenBy(r => r.DateSubmitted); } viewModel.Records = records .Select(r => MapRecord(r, category)) .ToArray(); for (int i = 0; i < viewModel.Records.Length; i++) { viewModel.Records[i].Rank = i + 1; } return(View(viewModel)); }