public IActionResult AddBook(Book bookToBeAdded) { IActionResult actionResult; try { libraryService.AddBook(new Data.Models.Book() { AuthorName = bookToBeAdded.AuthorName, BookName = bookToBeAdded.BookName, Category = bookToBeAdded.Category, Edition = bookToBeAdded.Edition, Price = bookToBeAdded.Price, Publisher = bookToBeAdded.Publisher }); actionResult = Created($"api/Books?bookName={bookToBeAdded.BookName}&authorName={bookToBeAdded.AuthorName}&publisher={bookToBeAdded.Publisher}", bookToBeAdded); } catch (Exception ex) { logger.LogError(ex, "Exception has occured"); actionResult = new StatusCodeResult(500); } return(actionResult); }
private void AddButton_Click(object sender, EventArgs e) { var title = TitleTextBox.Text; var author = TitleTextBox.Text; var rating = RatingTextBox.Text; var copies = CopiesTextBox.Text; var book = new Book(title, author, rating, int.Parse(copies)); service.AddBook(book); ClearTextBoxes(); DisplayBooks(); }