public async Task <User> RegisterAsync(UserBase model) { model.ValidateIsNotNull(nameof(model)); var userExists = await UserExistsAsync(model.Username); var emailInUse = await EmailInUseAsync(model.Email); if (userExists || emailInUse) { return(null); } var passwordSalt = CryptographyService.CreateSalt(); var passwordHash = CryptographyService.CreateHash(model.Password, passwordSalt); var entity = new Entities.User(); entity.PasswordHash = passwordHash; entity.PasswordSalt = passwordSalt; entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Username = model.Username; entity.DateOfBirth = model.DateOfBirth; entity.Email = model.Email; await _genericRepository.InsertAsync(entity); await _databaseScope.SaveChangesAsync(); return(_mapper.Map <User>(entity)); }
private static void UpdateEntity(UserBase model, Entities.User entity) { entity.FirstName = model.FirstName; entity.LastName = model.LastName; entity.Email = model.Email; entity.DateOfBirth = model.DateOfBirth; entity.Username = model.Username; }
public async Task <User> CreateAsync(UserBase model) { model.ValidateIsNotNull(nameof(model)); var entity = new Entities.User(); UpdateEntity(model, entity); await _genericRepository.InsertAsync(entity); await _databaseScope.SaveChangesAsync(); return(_mapper.Map <User>(entity)); }