示例#1
0
        public ActionResult EditGroup(int id = 0)
        {
            AdminRolePermissionTreeModel model = new AdminRolePermissionTreeModel();
            var userID = UserID;

            try
            {
                if (id == 0)
                {
                    model.Role = new AdminRoleInfo();
                }
                else
                {
                    model.Role = adminUserBLL.GetAdminRoleInfo(id);
                    if (model.Role == null)
                    {
                        throw new Exception();
                    }
                }
                var ModuleIDs = model.Role.ModuleIDList ?? new List <int>();
                var lstMenu   = adminUserBLL.GetAllMenuPermission();
                var dic       = lstMenu.ToDictionary(p => p.Permission,
                                                     p => new Tree <AdminMenuInfo>()
                {
                    Node        = p,
                    IsActive    = ModuleIDs.Contains(p.id) ? (bool?)true : null,
                    SubNodeList = new List <Tree <AdminMenuInfo> >()
                });
                foreach (var menu in lstMenu.Where(p => p.ParentPermission != EnumPermission.None))
                {
                    Tree <AdminMenuInfo> node;
                    if (dic.TryGetValue(menu.ParentPermission, out node))
                    {
                        node.SubNodeList.Add(dic[menu.Permission]);
                    }
                }
                var PermissionTree = new List <Tree <AdminMenuInfo> >();
                PermissionTree.AddRange(lstMenu.Where(p => p.ParentPermission == EnumPermission.None).Select(p => dic[p.Permission]));
                foreach (var node in PermissionTree.Where(p => p.IsActive == true))
                {
                    if (node.Exists(p => !p.IsActive.HasValue))
                    {
                        node.IsActive = false;
                    }
                }
                model.PermissionTree = PermissionTree;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
            }
            return(View(model));
        }