Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

UpdateEmailUsersCommand.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using AutoMapper;
  2. using BlackRock.Reporting.API.Models;
  3. using MediatR;
  4. namespace BlackRock.Reporting.API.Mediator
  5. {
  6. public class UpdateEmailUsersCommand : IRequest<Result<UserDto>>
  7. {
  8. public UserForm User { get; }
  9. public Guid Id { get; }
  10. public UpdateEmailUsersCommand(Guid id, UserForm user)
  11. {
  12. this.Id = id;
  13. this.User = user;
  14. }
  15. }
  16. public class UpdateEmailUsersCommandHandlers : IRequestHandler<UpdateEmailUsersCommand, Result<UserDto>>
  17. {
  18. private readonly ILogger<UpdateEmailUsersCommandHandlers> logger;
  19. private readonly IMapper mapper;
  20. public UpdateEmailUsersCommandHandlers(ILogger<UpdateEmailUsersCommandHandlers> logger, IMapper mapper)
  21. {
  22. this.mapper = mapper;
  23. this.logger = logger;
  24. }
  25. public async Task<Result<UserDto>> Handle(UpdateEmailUsersCommand command, CancellationToken cancellationToken)
  26. {
  27. if (command.Id == Guid.Empty)
  28. throw new ArgumentException($"Parameter {nameof(command.Id)} must not be null or empty");
  29. logger.LogInformation("Updating user email ...");
  30. try
  31. {
  32. var user = new User();
  33. // var user = repository.GetUserByIdAsync(id);
  34. user.Email = command.User.Email;
  35. // await unitOfWork.SaveChangesAsync();
  36. var updatedUser = mapper.Map<User, UserDto>(user);
  37. return new Result<UserDto> { Data = updatedUser };
  38. }
  39. catch (Exception ex)
  40. {
  41. return new Result<UserDto> { IsSuccess = false, Error = "Faild to update data in DB." };
  42. }
  43. }
  44. }
  45. }