// GET: Games public async Task <IActionResult> Index(DateTime?dayOf) { var viewModel = new GameIndexViewModel(); if (dayOf != null) { viewModel.dayOf = dayOf; } else { viewModel.dayOf = DateTime.Today.Date; } viewModel.Games = await _gamesService.GetGamesByDateAsync(viewModel.dayOf.Value); int count = 0; foreach (var g in viewModel.Games) { List <PlayerGameStats> leaders = await _playerGameStatsService.GetGameLeadersAsync(g.GameID); if (leaders.Count() == 2) { viewModel.Leaders[count++] = leaders[0]; viewModel.Leaders[count++] = leaders[1]; } } return(View(viewModel)); }
public async Task <IActionResult> Index() { var viewModel = new HomeIndexViewModel(); var last4Task = _gamesService.GetLastAsync(4); var next4Task = _gamesService.GetNextAsync(4); var newsTask = _newsService.GetNewsAsync(5); var myTeamsTask = _myTeamsService.GetMyTeamsByUserID(_userManager.GetUserId(User)); var viewTasks = new List <Task> { last4Task, next4Task, newsTask, myTeamsTask }; while (viewTasks.Any()) { Task finshed = await Task.WhenAny(viewTasks); if (finshed == last4Task) { viewTasks.Remove(last4Task); viewModel.Last4 = await last4Task; } else if (finshed == next4Task) { viewTasks.Remove(next4Task); viewModel.Next4 = await next4Task; } else if (finshed == newsTask) { viewTasks.Remove(newsTask); viewModel.News = await newsTask; } else if (finshed == myTeamsTask) { viewTasks.Remove(myTeamsTask); viewModel.MyTeams = await myTeamsTask; } else { viewTasks.Remove(finshed); } } int count = 0; foreach (var g in viewModel.Last4) { List <PlayerGameStats> leaders = await _playerGameStatsService.GetGameLeadersAsync(g.GameID); if (leaders.Count() == 2) { viewModel.Leaders[count++] = leaders[0]; viewModel.Leaders[count++] = leaders[1]; } } return(View(viewModel)); }