Example #1
0
        public IHttpActionResult UpdateById(int id, Book book)
        {
            BookDao bookExists = bookManagement.GetById(id);

            if (bookExists == null)
            {
                return(NotFound());
            }

            if (book.ISBN == 0 || book.Title == "" || book.Author == "" ||
                book.PublishYear == "" || book.Publisher == "" || book.Image == "" ||
                book.Summary == "" || book.Category == "" || book.Language == "")
            {
                return(BadRequest("Insufficient input"));
            }

            //Check if ISBN is greater than 0
            if (book.ISBN <= 0)
            {
                return(BadRequest("ISBN should be greater than 0"));
            }

            //Check if number of available books is not smaller or equal to 0
            if (book.NumberAvailable <= 0)
            {
                return(BadRequest("Number of available books must be greater than 0"));
            }

            //Calling the AddBook method to execute stored procedure
            string message = bookManagement.UpdateById(id, book.ISBN, book.Title, book.Author,
                                                       book.PublishYear, book.NumberAvailable, book.Publisher,
                                                       book.Image, book.Summary, book.Category, book.Language);

            if (message.Contains("Error"))
            {
                return(BadRequest(message));
            }

            return(Ok(message));
        }