示例#1
0
        public IActionResult ChangeLibraryForBook(long idBook, [FromBody] Book item)
        {
            if (item == null || item.bookid != idBook)
            {
                return(BadRequest());
            }
            var book = bookRepository.FindByID(idBook);

            if (book == null)
            {
                return(NotFound("Could not find book with id : " + idBook + ". Please try again with valid id."));
            }

            book.myLibrary = item.myLibrary;

            Book updatedBook = bookRepository.ChangeLibrary(book);

            if (updatedBook.bookid == -1)
            {
                return(NotFound("Destination library id : " + updatedBook.myLibrary.libraryid + " is not valid. Please try again"));
            }

            if (updatedBook.bookid == -2)
            {
                return(NotFound("Destination library id : " + updatedBook.myLibrary.libraryid + " is same as source library id."));
            }

            return(CreatedAtRoute("ChangeLibrary", new { idBook = idBook }, updatedBook));
        }