public IActionResult Create([FromBody] Book book)
 {
     if (book == null)
     {
         return(BadRequest());
     }
     return(Ok(_Books.CreateBook(book)));
 }
Beispiel #2
0
 public IActionResult AddBook(Book book)
 {
     if (ModelState.IsValid)
     {
         _books.CreateBook(book);
         return(RedirectToAction(nameof(Index)));
     }
     else
     {
         return(View());
     }
 }
Beispiel #3
0
        public IHttpActionResult CreateBook([FromBody] BookModel book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid book"));
            }
            var list = _Book.CreateBook(book);

            if (!list)
            {
                return(BadRequest("Coudln't create the book"));
            }

            return(Ok());
        }
Beispiel #4
0
        public IActionResult CreateBook(Book bookToCreate)
        {
            // Assert model state validation
            if (ModelState.IsValid)
            {
                // Create and store a new book in the database
                _bookRepository.CreateBook(bookToCreate);

                // Redirect to action
                return(RedirectToAction("BooksList"));
            }
            else
            {
                // Return view with data
                return(View(bookToCreate));
            }
        }