コード例 #1
0
 public ActionResult Update(int id)
 {
     using(var db = new PersonContext())
     {
         return View(db.Persons.Find(id));
     }
 }
コード例 #2
0
 public ActionResult DeleteConfirm(int id)
 {
     using(var db = new PersonContext())
     {
         return View(db.Persons.Find(id));
     }
 }
コード例 #3
0
 public ActionResult List()
 {
     using (var db = new PersonContext())
     {
         var persons = from p in db.Persons select p;
         return Json(persons.ToList(), JsonRequestBehavior.AllowGet);
     }
 }
コード例 #4
0
 public ActionResult Index()
 {
     using(var db = new PersonContext())
     {
         var persons = from p in db.Persons select p;
         return View(persons.ToList());
     }
 }
コード例 #5
0
 public ActionResult Update(Person person)
 {
     using(var db = new PersonContext())
     {
         db.Persons.Attach(person);
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
 }
コード例 #6
0
 public ActionResult Delete(int id)
 {
     using(var db = new PersonContext())
     {
         var p = db.Persons.Find(id);
         db.Entry(p).State = EntityState.Deleted;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
 }
コード例 #7
0
 public ActionResult Insert(Person person)
 {
     if (ModelState.IsValid)
     {
         using(var db = new PersonContext())
         {
             db.Persons.Add(person);
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     return View();
 }