public async Task <IActionResult> IncrementParameterValue(int parameterId, string userId)
        {
            if (await parametersRepository.FindParameterByIdAsync(parameterId) == null)
            {
                return(NotFound($"Parameter with Id {parameterId} not found"));
            }

            if (await userManager.FindByIdAsync(userId) == null)
            {
                return(NotFound($"User with Id {userId} not found"));
            }

            IActionResult result = NotFound(parameterId);

            try
            {
                await parameterValuesRepository.IncrementParamenterValueForUserAsync(parameterId, userId);

                var achievements = await achievementsRepository.GetAchievementsAsync();

                await achievementsManager.CheckAndUpdateСalculatedAchievementsForUser(userId, achievements.Select(a => a.Id));

                result = Redirect($"/Users/{userId}");
            }
            catch (Exception ex)
            {
                result = StatusCode(StatusCodes.Status500InternalServerError, ex);
            }

            return(result);
        }
Example #2
0
        private async Task <IEnumerable <AchievementProgressViewModel> > CreateAchievementsViewModel(User user)
        {
            var achievements = await achievementsRepository.GetAchievementsAsync();

            return(achievements.Select(a => new AchievementProgressViewModel()
            {
                AchievementId = a.Id,
                AchievementName = a.Name,
                AchievementType = a.AchievementType,
                IsReceived = user.UserAchievements.Any(ua => ua.AchievementId == a.Id)
            }));
        }