예제 #1
0
 public void SetUp()
 {
     _context.Products.RemoveRange(_context.Products);
     _context.Comments.RemoveRange(_context.Comments);
     _context.Users.RemoveRange(_context.Users);
     _context.SaveChanges();
 }
예제 #2
0
        public User Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }

            if (_context.Users.Any(x => x.Username == user.Username))
            {
                throw new AppException($"Username {user.Username} is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
예제 #3
0
 public void SetUp()
 {
     _context.Users.RemoveRange(_context.Users);
     _context.SaveChanges();
 }
예제 #4
0
 public bool Save()
 {
     return(_context.SaveChanges() >= 0);
 }