示例#1
0
 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");
 }
示例#2
0
        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 = "失败!" });
            }
        }
示例#3
0
 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");
 }