public async Task <UserDetail> Handle(GetUserByEmailQuery request, CancellationToken cancellationToken) { var userEntity = await _userRepository.GetUserByEmailAsync(request.EmailAddress); if (userEntity == null) { throw new ResourceNotFoundException("EmailAddress doesn't exist."); } return(_mapper.Map <UserEntity, UserDetail>(userEntity)); }
public async Task <UserDetail> Handle(CreateUserCommand request, CancellationToken cancellationToken) { var retrievedUser = await _userReadRepository.GetUserByEmailAsync(request?._User?.EmailAddress); if (retrievedUser != null) { throw new BadRequestException($"User with email address {request?._User?.EmailAddress} already exists."); } var userEntity = _mapper.Map <User, UserEntity>(request._User); userEntity.UserId = Guid.NewGuid(); await _userWriteRepository.CreateUserAsync(userEntity); return(_mapper.Map <UserEntity, UserDetail>(userEntity)); }