private async Task AddKudosRequestAsync(AddKudosLogDto kudosLog, decimal?points = null) { var kudosDto = await MapInitialInfoToDtoAsync(kudosLog, points); var receivingUsers = await _usersDbSet .Where(x => kudosLog.ReceivingUserIds.Contains(x.Id) && x.OrganizationId == kudosLog.OrganizationId) .ToListAsync(); var sendingUser = await _usersDbSet .FirstOrDefaultAsync(x => x.Id == kudosDto.SendingUser.Id && x.OrganizationId == kudosLog.OrganizationId); _kudosServiceValidator.CheckForEmptyUserList(receivingUsers); foreach (var receivingUser in receivingUsers) { _kudosServiceValidator.ValidateUser(receivingUser); kudosDto.ReceivingUser = _mapper.Map <ApplicationUserDto>(receivingUser); await ChooseKudosifyTypeAsync(kudosDto); } await _uow.SaveChangesAsync(false); if (kudosDto.KudosType.Type != KudosTypeEnum.Send) { return; } foreach (var receivingUser in receivingUsers) { _asyncRunner.Run <IKudosNotificationService>(async notifier => await notifier.NotifyAboutKudosSentAsync(kudosDto), _uow.ConnectionName); await UpdateProfileKudosAsync(receivingUser, kudosLog); } await UpdateProfileKudosAsync(sendingUser, kudosLog); }
private void AddKudosRequest(AddKudosLogDTO kudosLog, decimal?points = null) { var kudosDto = MapInitialInfoToDTO(kudosLog, points); var receivingUsers = _usersDbSet .Where(x => kudosLog.ReceivingUserIds.Contains(x.Id) && x.OrganizationId == kudosLog.OrganizationId) .ToList(); _kudosServiceValidator.CheckForEmptyUserList(receivingUsers); foreach (var receivingUser in receivingUsers) { _kudosServiceValidator.ValidateUser(receivingUser); kudosDto.ReceivingUser = receivingUser; ChooseKudosifyType(kudosDto); } _uow.SaveChanges(false); foreach (var receivingUser in receivingUsers) { if (kudosDto.KudosType.Type == ConstBusinessLayer.KudosTypeEnum.Send) { kudosDto.ReceivingUser = receivingUser; _kudosNotificationService.NotifyAboutKudosSent(kudosDto); UpdateProfileKudos(kudosDto.ReceivingUser, kudosLog); } } if (kudosDto.KudosType.Type == ConstBusinessLayer.KudosTypeEnum.Send) { UpdateProfileKudos(kudosDto.SendingUser, kudosLog); } }
private void AddKudosRequest(AddKudosLogDTO kudosLog, decimal?points = null) { var kudosDto = MapInitialInfoToDTO(kudosLog, points); var receivingUsers = _usersDbSet .Where(x => kudosLog.ReceivingUserIds.Contains(x.Id) && x.OrganizationId == kudosLog.OrganizationId) .ToList(); var sendingUser = _usersDbSet .FirstOrDefault(x => x.Id == kudosDto.SendingUser.Id && x.OrganizationId == kudosLog.OrganizationId); _kudosServiceValidator.CheckForEmptyUserList(receivingUsers); foreach (var receivingUser in receivingUsers) { _kudosServiceValidator.ValidateUser(receivingUser); kudosDto.ReceivingUser = _mapper.Map <ApplicationUserDTO>(receivingUser); ChooseKudosifyType(kudosDto); } _uow.SaveChanges(false); if (kudosDto.KudosType.Type != KudosTypeEnum.Send) { return; } foreach (var receivingUser in receivingUsers) { _asyncRunner.Run <IKudosNotificationService>(n => n.NotifyAboutKudosSent(kudosDto), _uow.ConnectionName); UpdateProfileKudos(receivingUser, kudosLog); } UpdateProfileKudos(sendingUser, kudosLog); }