public ActionResult Edit(RoleModel model) { using (DemoContext context = new DemoContext()) { Role item = context.Roles.FirstOrDefault(m => m.RoleID == model.RoleID); item.RoleName = model.RoleName; item.Description = model.Description; context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Create(RoleModel model) { try { using (DemoContext context = new DemoContext()) { context.Roles.Add(new Role { Description = model.Description, RoleName = model.RoleName }); context.SaveChanges(); } return Json(new { status = 1, msg = "成功!" }); } catch (Exception e) { return Json(new { status = 0, msg = "失败!" }); } }
public ActionResult Delete(int? RoleID) { using (DemoContext context = new DemoContext()) { Role item = context.Roles.FirstOrDefault(m => m.RoleID == RoleID); context.Roles.Remove(item); context.SaveChanges(); } return RedirectToAction("Index"); }