Beispiel #1
0
        public User Create(User user, string password)
        {
            // validation
            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);
        }
 public void Post([FromBody] Animal animal)
 {
     _db.Animals.Add(animal);
     _db.SaveChanges();
 }
 public void Post([FromBody] Breed breed)
 {
     _db.Breeds.Add(breed);
     _db.SaveChanges();
 }