private async Task <IEnumerable <IOrderedEnumerable <AchievementProgressViewModel> > > GetAchievementsProgressInGroups(string login)
        {
            var user = await userManager.Users
                       .Include(u => u.ParameterValues)
                       .Include(u => u.UserAchievements)
                       .FirstOrDefaultAsync(u => u.UserName == login);

            var groups = await achievementsGroupsRepository.GetAchievementsGroupsAsync();

            var semester = await semestersRepository.FindCurrentSemesterAsync();

            var progressGroups = new List <IOrderedEnumerable <AchievementProgressViewModel> >();

            foreach (var group in groups.Where(g => g.Ahievements.Any()))
            {
                var progressGroup = new List <AchievementProgressViewModel>();

                var filteredAchievements = semester == null ?
                                           group.Ahievements :
                                           group.Ahievements.Where(
                    a => a.SemesterId == null ||
                    a.SemesterId == semester.Id ||
                    user.UserAchievements.Any(ua => ua.AchievementId == a.Id)
                    );

                foreach (var achievement in filteredAchievements)
                {
                    var linkedParameterValue = user.ParameterValues.Where(pv => pv.ParameterId == achievement.ParameterId).FirstOrDefault();

                    var progress = new AchievementProgressViewModel()
                    {
                        AchievementId          = achievement.Id,
                        AchievementName        = achievement.Name,
                        AchievementDescription = achievement.Description,
                        NumberInGroup          = achievement.NumberInGroup,
                        AchievementValue       = achievement.AchievementValue,
                        LinkedParameterValue   = linkedParameterValue?.Value,
                        IsReceived             = user.UserAchievements.Any(ua => ua.AchievementId == achievement.Id),
                        AchievementType        = achievement.AchievementType
                    };
                    progressGroup.Add(progress);
                }
                progressGroups.Add(progressGroup.OrderBy(ap => ap.NumberInGroup));
            }

            return(progressGroups.Where(g => g.Any()));
        }
예제 #2
0
 private async Task <SelectList> CreateAchievementGroupsList(int?currentId)
 {
     return(new SelectList(await achievementsGroupsRepository.GetAchievementsGroupsAsync(), "Id", "Name", currentId));
 }
 public async Task <IActionResult> Index()
 {
     return(View(await achievementsGroupsRepository.GetAchievementsGroupsAsync()));
 }