Пример #1
0
 public ActionResult Save(RoleModel model)
 {
     try
     {
         switch (model.oper)
         {
             case oper.add:
                 {
                     return RedirectToAction("Create", model);
                 }
             case oper.edit:
                 {
                     return RedirectToAction("Edit", model);
                 }
             case oper.del:
                 {
                     return RedirectToAction("Delete", new { RoleID = model.id });
                 }
             default:
                 break;
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Пример #2
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");
 }
Пример #3
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 = "失败!" });
            }
        }