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)); }