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