Пример #1
0
        /// <summary>
        /// Adds a new book to the database
        /// ADMIN function
        /// </summary>
        public Book AddNewBook(Book newBook)
        {
            if (newBook == null)
            {
                throw new ObjectNotFoundException("Book not valid");
            }
            var book = new Book {
                Title         = newBook.Title,
                FirstName     = newBook.FirstName,
                LastName      = newBook.LastName,
                DatePublished = newBook.DatePublished,
                ISBN          = newBook.ISBN
            };

            _db.Add(book);
            _db.SaveChanges();
            if (book != null)
            {
                return(book);
            }
            else
            {
                throw new ObjectNotFoundException("Book not valid");
            }
        }
Пример #2
0
        /// <summary>
        /// Adds a new user to the database
        /// ADMIN function
        /// </summary>
        public Friend AddNewUser(Friend newUser)
        {
            if (newUser == null)
            {
                throw new Exception("User not valid");
            }
            var user = new Friend {
                FirstName = newUser.FirstName,
                LastName  = newUser.LastName,
                Email     = newUser.Email,
                Address   = newUser.Address
            };

            _db.Add(user);
            _db.SaveChanges();
            if (user != null)
            {
                return(user);
            }
            else
            {
                throw new Exception("Failed to add user to database");
            }
        }