Beispiel #1
0
        public User Create(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }


            if (_context.BookUsers.Any(x => x.Username == user.Username || x.Email == user.Email))
            {
                throw new Exception("Username \"" + user.Username + "\" or Email \"" + user.Email + " is already taken");
            }

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

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

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

            return(user);
        }
Beispiel #2
0
 public void Add(Genre genre)
 {
     genre.DateCreated = DateTime.Now;
     _context.Add(genre);
     _context.SaveChanges();
 }
Beispiel #3
0
 public void Add(Author author)
 {
     author.DateCreated = DateTime.Now;
     _context.Add(author);
     _context.SaveChanges();
 }
 public void Add(Publisher pub)
 {
     //pub.DateCreated = DateTime.Now;
     _context.Add(pub);
     _context.SaveChanges();
 }
Beispiel #5
0
 public void Add(Book book)
 {
     book.DateCreated = DateTime.Now;
     _context.Add(book);
     _context.SaveChanges();
 }
 public void Add(Category category)
 {
     category.DateCreated = DateTime.Now;
     _context.Add(category);
     _context.SaveChanges();
 }