public RaceCategoryResult(Data.Models.RaceCategory raceCategory) { /* * var orderedRunners = raceCategory.RaceRounds.SelectMany(x => x.RaceRoundUsers) * .GroupBy(x => x.RaceCategoryUserId).Select(x => new { userId = x.Key, time = x.Max(y => y.Time) }) * .OrderBy(x => x.time).Select((x, index) => new { userId = x.userId, time = x.time, order = index }); * * * * var orderedSubCategoryRunners = raceCategory.RaceSubCategories.ToDictionary(dic => dic.Id, * dic => dic.RaceCategoryUsers.SelectMany(x=>x.RaceRoundUsers) * .GroupBy(x => x.RaceCategoryUserId).Select(x => new { userId = x.Key, time = x.Max(y => y.Time) }) * .OrderBy(x => x.time).Select((x, index) => new { userId = x.userId, time = x.time, order = index })); */ Id = raceCategory.Id; Name = raceCategory.Name; SubCategoriesResults = raceCategory.RaceSubCategories.Select(x => new RaceSubCategoryResult { Id = x.Id, Name = x.Name, Rounds = x.RaceCategory.RaceRounds.Select(y => y.Name).ToList(), Runners = x.RaceCategoryUsers.Where(y => y.RunnerNumber.HasValue && y.RaceRoundUsers.Count > 0) .Select(y => new RaceRunnerRoundResult() { FirstName = y.ApplicationUser.FirstName, LastName = y.ApplicationUser.LastName, Times = y.RaceRoundUsers.Where(z => z.RaceCategoryUserId == y.Id).Select(z => z.Time).ToList(), RunnerNumber = y.RunnerNumber, CategoryOrder = /*orderedRunners.First(ou => ou.userId == y.Id).order + 1*/ y.OrderInCategory, SubCategoryOrder = /*orderedSubCategoryRunners.First(ou => ou.Key == x.Id).Value.First(ou => ou.userId == y.Id).order + 1*/ y.OrderInSubCategory }).ToList() }).ToList(); }
public ActionResult CategoryEdit(Models.Race.RaceCategory.RaceCategoryViewModel model) { if (ModelState.IsValid) { Data.Models.RaceCategory raceCategory; if (!model.Id.HasValue) { raceCategory = new Data.Models.RaceCategory(); raceCategory.RaceId = model.RaceId; } else { raceCategory = RaceCategoryRepository.GetById(model.Id.Value); } raceCategory.Name = model.Name; raceCategory.Description = model.Description; raceCategory.Start = model.Start.Value; if (model.Id.HasValue) { RaceCategoryRepository.Update(raceCategory, true); } else { RaceCategoryRepository.Create(raceCategory, true); } return(Content("OK")); } return(PartialView("/Views/Race/Category/Edit.cshtml", model)); }
public RaceCategoryViewModel(Data.Models.RaceCategory raceCategory, bool inDetail = false) { if (raceCategory != null) { Id = raceCategory.Id; Name = raceCategory.Name; RaceId = raceCategory.RaceId; Description = raceCategory.Description; Start = raceCategory.Start; canEdit = !raceCategory.Race.PublishDate.HasValue; if (inDetail) { RoundGridViewModel = new Round.RoundGridViewModel(raceCategory.Id, canEdit); SubCategoryGridViewModel = new SubCategory.SubCategoryGridViewModel(raceCategory.Id, canEdit); RaceRunnersGridViewModel = new RaceRunners.RaceRunnersGridViewModel(raceCategory.Id, true); } } }