Пример #1
0
        public async Task <MessageModel <DepartmentTree> > GetDepartmentTree(int pid = 0)
        {
            var departments = await _departmentServices.Query(d => d.IsDeleted == false);

            var departmentTrees = (from child in departments
                                   where child.IsDeleted == false
                                   orderby child.Id
                                   select new DepartmentTree
            {
                value = child.Id,
                label = child.Name,
                Pid = child.Pid,
                order = child.OrderSort,
            }).ToList();
            DepartmentTree rootRoot = new DepartmentTree
            {
                value = 0,
                Pid   = 0,
                label = "根节点"
            };

            departmentTrees = departmentTrees.OrderBy(d => d.order).ToList();


            RecursionHelper.LoopToAppendChildren(departmentTrees, rootRoot, pid);

            return(Success(rootRoot, "获取成功"));
        }
Пример #2
0
        //[Route("GetMenusTreeList")]
        //[AllowAnonymous]
        public async Task <BaseResponse <MenuTree> > GetMenusTreeList(int pid = 0)
        {
            var data        = new BaseResponse <MenuTree>();
            var permissions = await _menuServices.Query(d => d.IsDrop == false);

            var permissionTrees = (from child in permissions
                                   where child.IsDrop == false
                                   orderby child.Id
                                   select new MenuTree
            {
                value = child.Id,
                label = child.Name,
                Pid = child.ParentId,
                order = child.OrderSort,
            }).ToList();
            MenuTree rootRoot = new MenuTree
            {
                value = 0,
                Pid   = 0,
                label = "根节点"
            };

            permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();

            RecursionHelper.LoopToAppendChildren(permissionTrees, rootRoot, pid);
            data.Data = rootRoot;
            data.Msg  = "获取成功";
            return(data);
        }
Пример #3
0
        public async Task <MessageModel <PermissionTree> > GetPermissionTree(int pid = 0, bool needbtn = false)
        {
            var data = new MessageModel <PermissionTree>();

            var permissions = await _PermissionServices.Query(d => d.IsDeleted == false);

            var permissionTrees = (from child in permissions
                                   where child.IsDeleted == false
                                   orderby child.Id
                                   select new PermissionTree
            {
                value = child.Id,
                label = child.Name,
                Pid = child.Pid,
                isbtn = child.IsButton,
            }).ToList();
            PermissionTree rootRoot = new PermissionTree();

            rootRoot.value = 0;
            rootRoot.Pid   = 0;
            rootRoot.label = "根节点";

            RecursionHelper.LoopToAppendChildren(permissionTrees, rootRoot, pid, needbtn);

            data.success = true;
            if (data.success)
            {
                data.response = rootRoot;
                data.msg      = "获取成功";
            }

            return(data);
        }
Пример #4
0
        public async Task <MessageModel <PermissionTree> > GetPermissionTree(int pid = 0, bool needbtn = false)
        {
            var data    = new MessageModel <PermissionTree>();
            var roleIds = (await _userRoleServices.Query(d => d.IsDeleted == false && d.UserId == _user.ID)).Select(d => d.RoleId.ObjToInt()).Distinct().ToList();
            var pids    = (await _roleModulePermissionServices.Query(d => d.IsDeleted == false && roleIds.Contains(d.RoleId))).Select(
                d => d.PermissionId.ObjToInt()).Distinct();
            PermissionTree rootRoot = new PermissionTree
            {
                value = 0,
                Pid   = 0,
                label = "根节点"
            };

            if (pids.Any() || roleIds.Contains(1))//超级管理员
            {
                IOrderedEnumerable <Permission> rolePermissionMoudles;
                if (roleIds.Contains(1))
                {
                    rolePermissionMoudles = (await _permissionServices.Query(d => d.IsDeleted == false)).OrderBy(c => c.OrderSort);
                }
                else
                {
                    rolePermissionMoudles = (await _permissionServices.Query(d => pids.Contains(d.Id) && d.IsDeleted == false)).OrderBy(c => c.OrderSort);
                }
                var permissionTrees = (from child in rolePermissionMoudles
                                       orderby child.Id
                                       select new PermissionTree
                {
                    value = child.Id,
                    label = child.Name,
                    Pid = child.Pid,
                    isbtn = child.IsButton,
                    order = child.OrderSort,
                }).ToList();
                permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();
                RecursionHelper.LoopToAppendChildren(permissionTrees, rootRoot, pid, needbtn);
            }
            data.success = true;
            if (data.success)
            {
                data.response = rootRoot;
                data.msg      = "获取成功";
            }

            return(data);
        }
Пример #5
0
        public async Task <MessageModel <PermissionTree> > GetPermissionTree(int pid = 0, bool needbtn = false)
        {
            //var data = new MessageModel<PermissionTree>();

            var permissions = await _permissionServices.Query(d => d.IsDeleted == false);

            var permissionTrees = (from child in permissions
                                   where child.IsDeleted == false
                                   orderby child.Id
                                   select new PermissionTree
            {
                value = child.Id,
                label = child.Name,
                Pid = child.Pid,
                isbtn = child.IsButton,
                order = child.OrderSort,
            }).ToList();
            PermissionTree rootRoot = new PermissionTree
            {
                value = 0,
                Pid   = 0,
                label = "根节点"
            };

            permissionTrees = permissionTrees.OrderBy(d => d.order).ToList();


            RecursionHelper.LoopToAppendChildren(permissionTrees, rootRoot, pid, needbtn);

            //data.success = true;
            //if (data.success)
            //{
            //    data.response = rootRoot;
            //    data.msg = "获取成功";
            //}

            return(Success(rootRoot, "获取成功"));
            //return data;
        }