public string AddBook(Book book) { if (book != null) { using (BookDBContext contextObj = new BookDBContext()) { contextObj.books.Add(book); contextObj.SaveChanges(); return "Book record added successfully"; } } else { return "Invalid book record"; } }
public string UpdateBook(Book book) { if (book != null) { using (BookDBContext contextObj = new BookDBContext()) { int bookId = Convert.ToInt32(book.Id); Book _book = contextObj.books.Where(b => b.Id == bookId).FirstOrDefault(); _book.Title = book.Title; _book.Author = book.Author; _book.Publisher = book.Publisher; _book.Isbn = book.Isbn; contextObj.SaveChanges(); return "Book record updated successfully"; } } else { return "Invalid book record"; } }