public ActionResult Edit(EditRoleModel model)
 {
     Role role;
     if (_roleService.TryGetRole(model.Name, out role))
     {
         if (role.Id != model.Id)
         {
             //ModelState.AddModelError("Name", string.Format("角色名 {0} 已经存在", model.Name));
             throw new QsTechException(string.Format("角色名 {0} 已经存在", model.Name));
         }
     }
     if (ModelState.IsValid)
     {
         if (role == null)
         {
             role = _roleService.GetRole(model.Id);
         }
         role.Name = model.Name;
         role.Description = model.Description;
         role.Category = model.Category;
         role.BelongsTo = model.BelongsTo;
         ViewBag.Success = true;
     }
     else
     {
         ModelState.AddModelError("", this.GetModelErrorsMessage());
     }
     LoadPermissions(model, role);
     model.Navigations = _menuService.GetAllMenus().Where(m => m.Parent == null).ToList();
       //  var users = _userManager.GetUsers();
     //model.Owners = (from u in users
     //                join ru in role.Owners
     //                on u.Id equals ru
     //                select new RoleOwner
     //                {
     //                    Id = u.Id,
     //                    Name = u.Name
     //                }).ToList();
     model.BelongsArray = _belongsSystemService.GetSystems();
     return View(model);
 }
 void LoadPermissions(EditRoleModel model, Role role)
 {
     List<ModulePermissionModel> permissionModels = new List<ModulePermissionModel>();
     var modules = _moduleManager.GetAvailableModules();
     foreach (var module in modules)
     {
         var permissions = _permissionManager.GetPermissions(module.Id);
         if (!permissions.Any())
         {
             continue;
         }
         permissionModels.Add(new ModulePermissionModel
         {
             ModuleDescriptor = module,
             Permissions = permissions.Select(p => new PermissionModel
             {
                 PermissionName = _translation.T(p.Name),
                 PermissionDescription = p.Description,
                 Allow = role.Permissions != null && role.Permissions.Any(rp => rp == p.Name),
                 ImpliedPermissionString = p.ImpliedBy != null ? string.Join(",", p.ImpliedBy.Where(imp=>imp != null).Select(imp => imp.Name)) : string.Empty
             })
         });
     }
     model.Original = role;
     model.Permissions = permissionModels;
 }
        public ActionResult Edit(int id)
        {
            CheckPermission();
            var role = _roleService.GetRole(id);

            var model = new EditRoleModel(role);
            LoadPermissions(model, role);
            model.Navigations = _menuService.GetAllMenus().Where(m => m.Parent == null).ToList();
            //var users = _userManager.GetUsers();
            //model.Owners = (from u in users
            //                join ru in role.Owners
            //                on u.Id equals ru
            //                select new RoleOwner
            //                {
            //                    Id = u.Id,
            //                    Name = u.Name
            //                }).ToList();
            model.BelongsArray = _belongsSystemService.GetSystems();
            return View(model);
        }