コード例 #1
0
ファイル: BookController.cs プロジェクト: neenasusan/CBook
 public ActionResult AddOrEdit(Book bk)
 {
     using (CBookEntitiesBooks db = new CBookEntitiesBooks())
     {
         if (bk.BookID == 0)
         {
             var isExist = IsBNameExist(bk.BName);
             if (isExist)
             {
                 ModelState.AddModelError("BExist", "Book already Exist");
                 return(View(bk));
             }
             else
             {
                 db.Books.Add(bk);
                 db.SaveChanges();
                 return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
             }
         }
         else
         {
             db.Entry(bk).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
コード例 #2
0
ファイル: BookController.cs プロジェクト: neenasusan/CBook
 public ActionResult Delete(int id)
 {
     using (CBookEntitiesBooks db = new CBookEntitiesBooks())
     {
         Book bk = db.Books.Where(x => x.BookID == id).FirstOrDefault <Book>();
         db.Books.Remove(bk);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }