Ejemplo n.º 1
0
        public async Task <IActionResult> GetPermissionTree(string roleId)
        {
            var moduledata = await _moduleApp.GetList();

            var buttondata = await _moduleButtonApp.GetList();

            var authorizedata = new List <RoleAuthorizeEntity>();

            if (!string.IsNullOrEmpty(roleId))
            {
                authorizedata = await _roleAuthorizeApp.GetList(roleId);
            }
            var treeList = (from item in moduledata
                            let hasChildren = moduledata.Count(t => t.F_ParentId == item.F_Id) != 0
                                              select new TreeViewModel
            {
                id = item.F_Id,
                text = item.F_FullName,
                value = item.F_EnCode,
                parentId = item.F_ParentId,
                isexpand = true,
                complete = true,
                showcheck = true,
                checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id),
                hasChildren = true,
                img = item.F_Icon == "" ? "" : item.F_Icon
            }).ToList();

            treeList.AddRange(from item in buttondata
                              let hasChildren = buttondata.Any(t => t.F_ParentId == item.F_Id)
                                                select new TreeViewModel
            {
                id          = item.F_Id,
                text        = item.F_FullName,
                value       = item.F_EnCode,
                parentId    = item.F_ParentId == "0" ? item.F_ModuleId : item.F_ParentId,
                isexpand    = true,
                complete    = true,
                showcheck   = true,
                checkstate  = authorizedata.Count(t => t.F_ItemId == item.F_Id),
                hasChildren = hasChildren,
                img         = item.F_Icon == "" ? "" : item.F_Icon
            });
            return(Content(treeList.TreeViewJson()));
        }