コード例 #1
0
 public JsonResult UpdateRole(Models.RoleModel model)
 {
     if (ModelState.IsValid && model.Id > 0)
     {
         IDAL.IAuthoryRepository authoryRepository = EnterRepository.GetRepositoryEnter().GetAuthoryRepository;
         //判断权限名称是否已存在
         var result = authoryRepository.LoadEntities(m => m.Name == model.Name.Trim()).FirstOrDefault();
         if (result != null && result.Id != model.Id)
         {
             return(Json(new
             {
                 state = "error",
                 message = "角色名称已经存在了"
             }));
         }
         else
         {
             Model.Authory authory = new Model.Authory()
             {
                 Intro    = model.Intro,
                 Name     = model.Name,
                 OrderNum = model.OrderNum,
                 State    = model.State,
                 Id       = model.Id
             };
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.Get(m => m.Id == model.Id);
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.EditEntity(authory, new string[] { "Intro", "Name", "OrderNum", "State" });
             PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==成功", model.Name));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0)
             {
                 return(Json(new
                 {
                     state = "success",
                     message = "修改角色成功"
                 }));
             }
             else
             {
                 PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==失败", model.Name));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return(Json(new
                 {
                     state = "error",
                     message = "修改角色失败"
                 }));
             }
         }
     }
     else
     {
         return(Json(new
         {
             state = "error",
             message = "信息不完整"
         }));
     }
 }
コード例 #2
0
 public JsonResult UpdateRole(Models.RoleModel model)
 {
     if (ModelState.IsValid && model.Id > 0) {
         IDAL.IAuthoryRepository authoryRepository = EnterRepository.GetRepositoryEnter().GetAuthoryRepository;
         //判断权限名称是否已存在
         var result = authoryRepository.LoadEntities(m => m.Name == model.Name.Trim()).FirstOrDefault();
         if (result != null && result.Id != model.Id) {
             return Json(new {
                 state = "error",
                 message = "角色名称已经存在了"
             });
         }
         else {
             Model.Authory authory = new Model.Authory() {
                 Intro = model.Intro,
                 Name = model.Name,
                 OrderNum = model.OrderNum,
                 State = model.State,
                 Id = model.Id
             };
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.Get(m => m.Id == model.Id);
             EnterRepository.GetRepositoryEnter().GetAuthoryRepository.EditEntity(authory, new string[] { "Intro", "Name", "OrderNum", "State" });
             PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==成功", model.Name));
             if (EnterRepository.GetRepositoryEnter().SaveChange() > 0) {
                 return Json(new {
                     state = "success",
                     message = "修改角色成功"
                 });
             }
             else {
                 PublicFunction.AddOperation(1, string.Format("修改角色"), string.Format("修改角色=={0}==失败", model.Name));
                 EnterRepository.GetRepositoryEnter().SaveChange();
                 return Json(new {
                     state = "error",
                     message = "修改角色失败"
                 });
             }
         }
     }
     else {
         return Json(new {
             state = "error",
             message = "信息不完整"
         });
     }
 }