public async Task <IResponse> AddAsync(CreateRequestAchievementModel model, Guid userId, CancellationToken cancellationToken) { var user = await _userRepository.GetByIdAsync(userId, cancellationToken); var achievement = await _achievementRepository.GetByIdAsync(model.AchievementId, cancellationToken); var requestAchievementPage = _stringLocalizer["RequestAchievementPage"].ToString(); var pageWithParams = requestAchievementPage.Replace("{userLastName}", user.LastName); pageWithParams = pageWithParams.Replace("{userFirstName}", user.FirstName); pageWithParams = pageWithParams.Replace("{message}", model.Message); pageWithParams = pageWithParams.Replace("{achievementName}", achievement.Name); var emails = await _userRepository.GetAdminsEmailsAsync(cancellationToken); await _emailService.SendEmailsAsync("Request achievement", pageWithParams, cancellationToken, emails.ToArray()); var entity = _mapper.Map <RequestAchievement>(model); entity.UserId = userId; await _requestAchievementRepository.AddAsync(entity, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); return(new OkResponse()); }
public async Task DeleteAchievementAsync(Guid id, CancellationToken cancellationToken) { var achievement = await _achievementRepository.GetByIdAsync(id, cancellationToken); _achievementRepository.Delete(achievement); await _unitOfWork.SaveChangesAsync(cancellationToken); }
public async Task AddAsync(Guid userId, Guid achievementId, CancellationToken cancellationToken) { var user = await _userRepository.GetByIdAsync(userId, cancellationToken); var achievement = await _achievementRepository.GetByIdAsync(achievementId, cancellationToken); var userAchievement = new UserAchievement() { User = user, Achievement = achievement }; user.XP += achievement.XP; _userRepository.Update(user); user.Achievements.Add(userAchievement); await _userAchievementRepository.AddAsync(userAchievement, cancellationToken); await CreateEventAsync(user, $"Got achievement {achievement.Name}", GamificationEnums.EventType.Records, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); }
private async Task <bool> CheckNameAsync(string name, CancellationToken cancellationToken) { var achievementId = GetAchievementId(); var achievementEntity = await _achievementRepository.GetByIdAsync(achievementId, cancellationToken); if (achievementEntity.Name == name) { return(true); } var achievement = await _achievementRepository.GetAchievementByNameAsync(name, cancellationToken); if (achievement == null) { return(true); } return(achievementEntity.Id == achievement.Id); }