예제 #1
0
        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);
        }
예제 #2
0
 public void Save()
 {
     _context.SaveChanges();
 }
예제 #3
0
 public void Commit()
 {
     _context.SaveChanges();
 }