public async Task <IActionResult> AddBook([FromBody] SimpleBook vm) { if (ModelState.IsValid) { var book = new Book() { Id = vm.Id, Title = vm.Title, Price = vm.Price, Description = vm.Description, CoverPage = vm.CoverPage, Tags = vm.Tags, Author = authorManager.GetAuthorById(vm.Author) }; bookManager.AddBook(book); vm.Id = book.Id; await bookHub.Clients.All.SendAsync("BookAdded", vm); return(Created($"/api/books/{book.Id}", vm)); } else { return(BadRequest(ModelState)); } }
public BookErrorCodes AddNewBook(string title, string author, double cost, long ISBN, int shelfID) { var existingShelf = shelfManager.GetShelf(shelfID); if (existingShelf == null) { return(BookErrorCodes.NoSuchShelf); } if (ValidateISBN(ISBN) == false) { return(BookErrorCodes.IncorrectISBN); } var sameBooks = bookManager.GetListOfBooksByTitle(title); if (sameBooks.Count > 0) { bookManager.AddBook(title, author, cost, ISBN, sameBooks.First().ShelfID); return(BookErrorCodes.OkButBookIsPutInAnotherShelfWithExistingBooks); } else { bookManager.AddBook(title, author, cost, ISBN, shelfID); } return(BookErrorCodes.ok); }
public bool AddBook(string bookName, int bookPrice) { var existingBook = bookManager.GetBookByBookName(bookName); if (existingBook != null) { return(false); } bookManager.AddBook(bookName, bookPrice); return(true); }
public bool AddBook(int bookNumber) { var existingBook = bookManager.GetBookByNumber(bookNumber); if (existingBook != null) { return(false); } bookManager.AddBook(bookNumber); return(true); }
public bool AddBook(string bookName, int costPrice, long ISBNNumber, bool isValid, bool inLibrary, int bookCondition) { var existingBook = bookManager.GetBookByName(bookName, inLibrary, bookCondition); if (existingBook != null) { return(false); } bookManager.AddBook(bookName, costPrice, ISBNNumber, isValid, inLibrary, bookCondition); return(true); }
public async Task <IActionResult> Create(Book book) { if (ModelState.IsValid) { var respuesta = await _bookManager.AddBook(book); if (respuesta) { return(RedirectToAction("Index")); } } return(View(book)); }
public AddBookStatusCodes AddBook(string iSBNNumber, string bookTitle, string author, int price, int condition, int shelfNumber, int aisleNumber) { var existingShelf = shelfManager.GetShelfFromAisle(shelfNumber, aisleNumber); var purchaseYear = DateTime.Today.Year; if (existingShelf == null) { return(AddBookStatusCodes.NoSuchShelf); } bookManager.AddBook(iSBNNumber, bookTitle, author, purchaseYear, price, condition, existingShelf, false, null); return(AddBookStatusCodes.Ok); }
public BookStatusCodes AddBook(string bookTitle, string bookAuthor, string isbnNumber, int bookPrice, int purchaseYear, int bookCondition, Shelf shelf, bool isLoaned) { var existingBook = bookManager.GetBookByBookTitle(bookTitle); if (existingBook != null) { return(BookStatusCodes.BookAlreadyExist); } if (CheckValidIsbn(isbnNumber) == false) { return(BookStatusCodes.InvalidIsbnNumber); } bookManager.AddBook(bookTitle, bookAuthor, isbnNumber, bookPrice, purchaseYear, bookCondition, shelf, isLoaned); return(BookStatusCodes.Ok); }
/// <summary> /// Parses the json message sent and converts it into a BookImpl object using a json serializer. /// </summary> /// <param name="json"> the json message to be parsed.</param> /// <exception cref="ArgumentException"> thrown if the json message is null or empty.</exception> private void ProcessNewBookUpdate(string json) { if (String.IsNullOrEmpty(json)) { throw new ArgumentException("json"); } try { IBook newBook = JsonConvert.DeserializeObject <BookImpl>(json); bookManager.AddBook(newBook.BookCode, newBook.Entity, newBook.IsValid); } catch (Exception exc) { log.Error(String.Format("Failed to deserialize json [{0}] into new book update. Exception raised [{1}]", json, exc.Message)); } }
public ErrorCodesAddBook AddBook(string bookTitle, string authorOfBook, string isbn, int purchaseYear, int conditionOfBook, int purchasePrice, int bookNumber, bool activeLoan, int shelfNumber, int pathID) { var exsitingBook = bookManager.GetBookByBookNumber(bookNumber); var exsistingShelf = shelfManager.GetShelfByShelfNumber(shelfNumber, pathID); if (exsitingBook != null) { return(ErrorCodesAddBook.BookAlreadyExsist); } if (isbn.Length != 13) { return(ErrorCodesAddBook.InvalidISBN); } if (exsistingShelf == null) { return(ErrorCodesAddBook.BookNeedsAShelf); } bookManager.AddBook(bookTitle, authorOfBook, isbn, purchaseYear, conditionOfBook, purchasePrice, bookNumber, activeLoan, shelfNumber, pathID); return(ErrorCodesAddBook.Ok); }
public AddBookErrorCodes AddBook(int bookNumber, string bookTitle, string bookAuthor, string isbnNumber, int bookCondition) { if (string.IsNullOrEmpty(isbnNumber)) { return(AddBookErrorCodes.ThereIsNoISBNumber); } if (ValidateISBN(isbnNumber) == false) { return(AddBookErrorCodes.ISBNNumberNotValid); } if (string.IsNullOrEmpty(bookAuthor)) { return(AddBookErrorCodes.BookNotGivenAnAuthor); } if (string.IsNullOrEmpty(bookTitle)) { return(AddBookErrorCodes.BookNotGivenATitle); } bookManager.AddBook(bookNumber, bookTitle, bookAuthor, isbnNumber, bookCondition); return(AddBookErrorCodes.Ok); }
public async Task <IActionResult> PostBook(Book book) { var respuesta = await _bookManager.AddBook(book); return(Json(respuesta)); }
public void Return_Unsuccessful_When_Receives_null() { var result = bookManager.AddBook(null); Assert.False(result.Successful); }