public UserVm CreateUser(UserVm userVm) { UserModel user = _mapper.Map <UserModel>(userVm); if (string.IsNullOrWhiteSpace(user.Password)) { throw new AppException("Password is required"); } if (_context.UserModels.Any(x => x.EmailAddress == user.EmailAddress)) { throw new AppException("Username " + user.EmailAddress + " is already taken"); } var paswordHash = HashPassword(user.Password); user.Password = paswordHash; //_userRepository.CreateUser(user); _context.Add(user); _context.SaveChanges(); var userConfirmation = _context.UserModels.SingleOrDefault(x => x.EmailAddress == user.EmailAddress); var userReturned = new UserVm(); if (userConfirmation != null) { return(userReturned = _mapper.Map <UserVm>(userConfirmation)); } return(userReturned); }
public void Save() { _context.SaveChanges(); }
public void Commit() { _context.SaveChanges(); }