public List <Score> SortScores() { var scoresVm = _usersRolesAndScoresRepo.GetBestResults().ProjectTo <ScoreVm> (_mapper.ConfigurationProvider).ToList(); var sortedList = scoresVm.OrderBy(i => i.BestResult).Reverse().ToList(); for (int i = 1; i <= sortedList.Count; i++) { if (i != 1) { if (sortedList[i - 1].BestResult != sortedList[i - 2].BestResult) { sortedList[i - 1].Place = i; } else { sortedList[i - 1].Place = i - 1; } } else { sortedList[0].Place = 1; } } List <Score> Scores = new List <Score>(); foreach (var item in sortedList) { var score = _mapper.Map <Score>(item); Scores.Add(score); } _usersRolesAndScoresRepo.SavePlaceOnScoreBoard(Scores); return(Scores); }
public StatsOfUsersVm GetStatsAboutUsers() { List <string> superAdmins = new List <string>(); List <string> admins = new List <string>(); List <string> usualUsers = new List <string>(); var users = _usersRolesAndScoresRepo.GetUsers().ProjectTo <UserAndRoleVm> (_mapper.ConfigurationProvider).ToList(); foreach (var item in users) { if (item.UserRoles[0].Role.Id == "SuperAdmin") { superAdmins.Add(item.UserName); } else if (item.UserRoles[0].Role.Id == "Admin") { admins.Add(item.UserName); } else if (item.UserRoles[0].Role.Id == "User") { usualUsers.Add(item.UserName); } } var bestScores = _usersRolesAndScoresRepo.GetBestResults().ProjectTo <ScoreVm> (_mapper.ConfigurationProvider).ToList(); var sortedList = bestScores.OrderBy(i => i.BestResult).Reverse().ToList(); StatsOfUsersVm statsOfUsersVm = new StatsOfUsersVm() { NumberOfRegisteredUsers = users.Count, NumberOfSuperAdmins = superAdmins.Count(), EmailsOfSuperAdmins = superAdmins, NumberOfAdmins = admins.Count(), EmailsOfAdmins = admins, NumberOfUsualUser = usualUsers.Count(), EmailsOfUsualUser = usualUsers, TheBestScore = sortedList[0].BestResult, EmailOfTheBestPlayer = sortedList[0].UserLogin, TheWorstScore = sortedList[sortedList.Count() - 1].BestResult, EmailOfTheWorstPlayer = sortedList[sortedList.Count() - 1].UserLogin }; return(statsOfUsersVm); }