public ActionResult TournamentUsers(int tournamentId) { var usersActive = _tournamentManager.TournamentsUsers .Where(x => x.TournamentId == tournamentId) .ToList(); var usersHistory = _tournamentManager.HistoryTournamentsUsers .Where(x => x.TournamentId == tournamentId) .ToList(); var viewModel = new ListOfUsersViewModel(); var listOfActiveUsers = new List<PersonScoreViewModel>(); var listOfHistoryUsers = new List<PersonScoreViewModel>(); usersActive.ForEach(x => { var user = new PersonScoreViewModel { FirstName = x.User.FirstName, LastName = x.User.LastName }; listOfActiveUsers.Add(user); }); usersHistory.ForEach(x => { ApplicationUser u = UserManager.FindByIdAsync(x.UserId).Result; var user = new PersonScoreViewModel { FirstName = u.FirstName, LastName = u.LastName }; listOfHistoryUsers.Add(user); }); viewModel.ActiveUsers = listOfActiveUsers; viewModel.HistoryUsers = listOfHistoryUsers; return View(viewModel); }
public ActionResult Index(int tournamentId) { var viewModel = new ScoresViewModel(); var currentScoresViewModel = new PhaseScoresViewModel(); var historyScoresViewModel = new List<PhaseScoresViewModel>(); var dbCurrentScores = _scoreManager.Scores .Where(x => x.TournamentId == tournamentId) .OrderByDescending(x => x.TotalScore) .ToList(); var currentPersonalScoresViewModel = new List<PersonScoreViewModel>(); dbCurrentScores.ForEach(x => { currentScoresViewModel.PhaseTitle = x.Phase.Name; PersonScoreViewModel personScoreViewModel = new PersonScoreViewModel { FirstName = x.User.FirstName, LastName = x.User.LastName, Score = x.TotalScore }; currentPersonalScoresViewModel.Add(personScoreViewModel); }); currentScoresViewModel.Scores = currentPersonalScoresViewModel; var dbHistoryScores = _scoreManager.HistoryScores .Where(x => x.TournamentId == tournamentId) .OrderByDescending(x => x.TotalScore) .GroupBy(x => x.PhaseId) .ToList(); foreach (var phase in dbHistoryScores) { var historyPhase = new PhaseScoresViewModel(); var personalScoresList = new List<PersonScoreViewModel>(); foreach (var personalScore in phase) { historyPhase.PhaseTitle = personalScore.Phase.Name; var person = new PersonScoreViewModel { FirstName = personalScore.User.FirstName, LastName = personalScore.User.LastName, Score = personalScore.TotalScore }; personalScoresList.Add(person); } historyPhase.Scores = personalScoresList; historyScoresViewModel.Add(historyPhase); } viewModel.CurrentPhase = currentScoresViewModel; viewModel.HistoryPhases = historyScoresViewModel; return View(viewModel); }