예제 #1
0
        public ActionResult UpdateRole(RoleModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new eXmlContext())
                    {
                        var role = db.Set<Role>()
                            .SingleOrDefault(x => x.RoleId == model.RoleId);

                        role.RoleName = model.RoleName;
                        role.RoleType = model.RoleType;

                        db.Entry(role).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }

            }
            else
            {
                ViewData["EditError"] = "Please correct all errors";
                ViewData["Role"] = model;
            }
            return PartialView("_GridListRoles", AdminServiceProvider.Roles());
        }
예제 #2
0
 public ActionResult AddRole(RoleModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Role r = new Role
             {
                 RoleName = model.RoleName,
                 RoleType = model.RoleType
             };
             using (var db = new eXmlContext())
             {
                 db.Roles.Add(r);
                 db.SaveChanges();
             }
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
     {
         ViewData["EditError"] = "Please correct all errors";
         ViewData["Role"] = model;
     }
     return PartialView("_GridListRoles", AdminServiceProvider.Roles());
 }