public Model.Account Update(int accountId, InsertAccountRequest request) { var account = _context.Accounts.Find(accountId); foreach (var acc in _context.Accounts.ToList()) { if (acc.Username == request.Username && acc.Username != account.Username) { throw new UserException("The username is taken"); } } account.Username = request.Username; if (request.Password != null) { if (request.Password != request.ConfirmPassword) { throw new UserException("Passwords are not matching"); } account.PasswordSalt = GenerateSalt(); account.PasswordHash = GenerateHash(account.PasswordSalt, request.Password); } _context.SaveChanges(); return(_mapper.Map <Model.Account>(account)); }
public async Task InsertAsync(InsertAccountRequest request) { using (var unitOfWork = _unitOfWorkFactory.StartUnitOfWork()) { await _accountService.InsertAsync( _mapper.Map <Account>(request)); unitOfWork.Save(); } }
public async Task <InsertAccountResult> InsertAccountAsync(InsertAccountRequest insertAccountRequest) { return(await _sqlService .QueryFirstAsync <InsertAccountResult> ( _dickinsonBrosDB.ConnectionString, INSERT_ACCOUNT, insertAccountRequest, commandType : CommandType.StoredProcedure )); }
public async Task <IActionResult> Insert( [FromBody] InsertAccountRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _accountAppService.InsertAsync(request); return(Ok()); }
public Model.Account Insert(InsertAccountRequest request) { if (request.Password != request.ConfirmPassword) { throw new UserException("Passwords are not matching"); } foreach (var acc in _context.Accounts.ToList()) { if (acc.Username == request.Username) { throw new UserException("The username is taken"); } } var account = _mapper.Map <Database.Account>(request); account.PasswordSalt = GenerateSalt(); account.PasswordHash = GenerateHash(account.PasswordSalt, request.Password); _context.Accounts.Add(account); _context.SaveChanges(); return(_mapper.Map <Model.Account>(_mapper.Map <Database.Account>(account))); }