コード例 #1
0
ファイル: RoleController.cs プロジェクト: vebin/base
        /// <summary>
        ///
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        private async Task <List <TreeModel> > GetPermissionTree(long?roleId)
        {
            var moduledata    = (await ModuleApp.GetSaasModuleListAsync()).OrderBy(o => o.SortCode).ToList();
            var buttondata    = (await ModuleButtonApp.GetSaasModuleListAsync()).OrderBy(o => o.SortCode).ToList();
            var authorizedata = new List <RoleAuthorize>();

            if (roleId.HasValue)
            {
                authorizedata = (await RoleAuthorizeApp.GetListAsync(roleId.Value, 1)).ToList();
            }
            var treeList = new List <TreeModel>();

            foreach (var item in moduledata)
            {
                var tree = new TreeModel
                {
                    Id          = item.Id,
                    Text        = item.FullName,
                    Value       = item.Id.ToString(),
                    Parentnodes = item.ParentId,
                    Isexpand    = true,
                    Complete    = false,
                    Showcheck   = true,
                    Checkstate  = authorizedata.Count(t => t.ItemId == item.Id),
                    HasChildren = false,
                    Img         = item.Icon == "" ? "" : item.Icon
                };
                treeList.Add(tree);
            }

            foreach (var item in buttondata)
            {
                var tree = new TreeModel
                {
                    Id          = item.Id,
                    Text        = item.FullName,
                    Value       = item.Id.ToString(),
                    Parentnodes = item.ParentId == 0 ? item.ModuleId : item.ParentId,
                    Isexpand    = true,
                    Complete    = false,
                    Showcheck   = true,
                    Checkstate  = authorizedata.Count(t => t.ItemId == item.Id),
                    HasChildren = false,
                    Img         = item.Icon == "" ? "" : item.Icon
                };
                treeList.Add(tree);
            }
            return(treeList);
        }
コード例 #2
0
        // 列表
        // GET: /<controller>/     [Bind(Prefix ="")]
        public async Task <IActionResult> Index(ModuleOption option)
        {
            //返回json
            if (Request.IsAjaxRequest())
            {
                List <Module> modules = await ModuleApp.GetSaasModuleListAsync(option);

                return(Json(new { rows = modules }));
            }
            //菜单数据
            var data = await ModuleApp.GetSaasModuleListAsync();

            ViewData["tree"] = JsonHelper.SerializeObject(await Trees(data, 0), true, true); //json long 转成 string, 名称用驼峰结构输出
            return(View());
        }