Esempio n. 1
0
 public ActionResult Index()
 {
     using (DemoContext context = new DemoContext())
     {
         List<Role> list = context.Roles.ToList();
         return View(list);
     }
 }
Esempio n. 2
0
        public JsonResult GetData(string sidx, string sord, int page, int rows)
        {
            using (DemoContext context = new DemoContext())
            {

                JsonResult result = context.Roles.GetJson(sidx, sord, page, rows, JsonRequestBehavior.AllowGet, new string[] { "RoleID", "RoleName", "Description" });
                return result;
            }
        }
Esempio n. 3
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");
 }
Esempio n. 4
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 = "失败!" });
            }
        }
Esempio n. 5
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");
 }