Пример #1
0
 public async Task HandleAsync(UsernameChanged @event)
 {
     await _handler
     .Run(async() =>
     {
         var settings            = await _settingsService.GetSettingsAsync(@event.UserId);
         settings.Value.Username = @event.NewName;
         await _settingsService.UpdateSettingsAsync(settings.Value);
     })
     .OnError((ex, logger) => logger.Error(ex, $"Error while updating username, userId: {@event.UserId}"))
     .ExecuteAsync();
 }
Пример #2
0
 public async Task HandleAsync(SignedUp @event)
 {
     await _handler
     .Run(async() =>
     {
         var user = await _userServiceClient.GetAsync(@event.UserId);
         if (user.HasNoValue)
         {
             throw new ServiceException(OperationCodes.ResourceNotFound,
                                        $"User with id: {@event.UserId} cannot be found");
         }
         var culture  = GetCulture(user.Value.Culture);
         var settings = UserNotificationSettings.Create(@event.UserId,
                                                        user.Value.Email, user.Value.Name, culture);
         await _settingsService.UpdateSettingsAsync(settings);
     })
     .OnError((ex, logger) => logger.Error(ex, $"Error while handling user SignedUp event, userId: {@event.UserId}"))
     .ExecuteAsync();
 }
Пример #3
0
 public async Task HandleAsync(UpdateUserNotificationSettings command)
 {
     await _handler
     .Run(async() =>
     {
         var settings = _mapper.Map <UserNotificationSettings>(command);
         await _settingsService.UpdateSettingsAsync(settings);
     })
     .OnSuccess(async() =>
     {
         await _bus
         .PublishAsync(new UserNotificationSettingsUpdated(
                           command.Request.Id, command.UserId));
     })
     .OnError(async(ex, logger) =>
     {
         logger.Error(ex, "Error occured while updating user notification settings");
         await _bus.PublishAsync(new UpdateUserNotificationSettingsRejected(
                                     command.Request.Id, command.UserId,
                                     OperationCodes.CannotUpdateUserNotificationSettings, ex.Message));
     })
     .ExecuteAsync();
 }