Ejemplo n.º 1
0
        public async Task <AccountResponseDto> CreateAsync(CreateAccountRequestDto request)
        {
            await _createAccountRequestValidator.ValidateAndThrowAsync(request);

            // validate
            if (_dbContext.Accounts.Any(x => x.Email == request.Email))
            {
                throw new AppException($"Email '{request.Email}' is already registered");
            }

            // map model to new account object
            var account = _mapper.Map <Account>(request);

            account.CreatedDate = DateTime.UtcNow;
            account.Verified    = DateTime.UtcNow;

            // hash password
            account.PasswordHash = BC.HashPassword(request.Password);

            // save account
            _dbContext.Accounts.Add(account);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <AccountResponseDto>(account));
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <AccountResponseDto> > CreateAsync(CreateAccountRequestDto model)
 {
     return(Ok(await _accountService.CreateAsync(model)));
 }