| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using AutoMapper;
- using BlackRock.Reporting.API.Models;
- using MediatR;
-
- namespace BlackRock.Reporting.API.Mediator
- {
- public class UpdateEmailUsersCommand : IRequest<Result<UserDto>>
- {
- public UserForm User { get; }
- public Guid Id { get; }
- public UpdateEmailUsersCommand(Guid id, UserForm user)
- {
- this.Id = id;
- this.User = user;
- }
- }
-
- public class UpdateEmailUsersCommandHandlers : IRequestHandler<UpdateEmailUsersCommand, Result<UserDto>>
- {
- private readonly ILogger<UpdateEmailUsersCommandHandlers> logger;
- private readonly IMapper mapper;
- public UpdateEmailUsersCommandHandlers(ILogger<UpdateEmailUsersCommandHandlers> logger, IMapper mapper)
- {
- this.mapper = mapper;
- this.logger = logger;
- }
- public async Task<Result<UserDto>> Handle(UpdateEmailUsersCommand command, CancellationToken cancellationToken)
- {
- if (command.Id == Guid.Empty)
- throw new ArgumentException($"Parameter {nameof(command.Id)} must not be null or empty");
- logger.LogInformation("Updating user email ...");
- try
- {
- var user = new User();
- // var user = repository.GetUserByIdAsync(id);
- user.Email = command.User.Email;
- // await unitOfWork.SaveChangesAsync();
- var updatedUser = mapper.Map<User, UserDto>(user);
- return new Result<UserDto> { Data = updatedUser };
- }
- catch (Exception ex)
- {
- return new Result<UserDto> { IsSuccess = false, Error = "Faild to update data in DB." };
- }
- }
- }
- }
|