public async Task <HomeDisplayModel> GetHomeDisplayModel() { var roundsNextUp = (await GetRoundsNextUp()).ToList(); var roundsNextUpDisplayModels = (await roundsNextUp .OrderBy(n => n.Date) .SelectAsync(async n => { var eventHistory = await _roundService.GetEventHistory(n.Id); return(new NextUpDisplayModel(n, roundsNextUp, eventHistory)); })) .ToList(); var veryNextUp = roundsNextUpDisplayModels .FirstOrDefault(n => n.IsVeryNextUp); var allSeasons = await _context.Season .Include(s => s.RelatedRounds) .Select(s => new HomeDisplayModel.SeasonDisplayModelForHome(s)) .ToListAsync(); var roundsToAcquire = (await GetRoundsToAcquire()).ToList(); return(new HomeDisplayModel { VeryNextUp = veryNextUp, NextUp = roundsNextUpDisplayModels .Where(n => veryNextUp == null || n != veryNextUp) .ToList(), RoundsToAcquire = roundsToAcquire .Select(r => new RoundToAcquireDisplayModel(r)) .OrderBy(r => r.Date) .ThenBy(r => r.Sport) .ToList(), LatestSeasons = allSeasons .GroupBy(s => s.Sport) .Select( group => new { Sport = group.Key, Seasons = group .OrderByDescending(s => s.StartDate ?? DateTime.MaxValue) .Take(2) .AsEnumerable() }) .SelectMany(_ => _.Seasons) .OrderByDescending(s => s.StartDate ?? DateTime.MaxValue) .ToList() }); }
// GET: Rounds/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var round = await _roundService.LoadDisplayModel(id.Value); if (round == null) { return(NotFound()); } var eventHistory = await _roundService.GetEventHistory(round.Id); var displayModel = new RoundDetailDisplayModel(round, eventHistory); return(View(displayModel)); }