コード例 #1
0
 // Add book
 public string AddBook(Book book)
 {
     if (book != null)
     {
         using (BookDBContext contextObj = new BookDBContext())
         {
             contextObj.book.Add(book);
             contextObj.SaveChanges();
             return "Book record added successfully";
         }
     }
     else
     {
         return "Invalid book record";
     }
 }
コード例 #2
0
 //Update Book
 public string UpdateBook(Book book)
 {
     if (book != null)
     {
         using (BookDBContext contextObj = new BookDBContext())
         {
             int bookId = Convert.ToInt32(book.Id);
             Book _book = contextObj.book.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";
     }
 }