コード例 #1
0
        public async Task <MessageModel <PageModel <Permission> > > Get(int page = 1, string key = "", int intPageSize = 50)
        {
            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }

            Expression <Func <Permission, bool> > whereExpression = a => a.Id > 0;

            return(new MessageModel <PageModel <Permission> >()
            {
                msg = "获取成功",
                success = true,
                response = await _permissionServices.QueryPage(whereExpression, page, intPageSize)
            });
        }
コード例 #2
0
        public async Task <MessageModel <PageModel <Permission> > > Get(int page = 1, string key = "")
        {
            PageModel <Permission> permissions = new PageModel <Permission>();
            int intPageSize = 50;

            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }

            #region  弃
            //var permissions = await _permissionServices.Query(a => a.IsDeleted != true);
            //if (!string.IsNullOrEmpty(key))
            //{
            //    permissions = permissions.Where(t => (t.Name != null && t.Name.Contains(key))).ToList();
            //}
            ////筛选后的数据总数
            //totalCount = permissions.Count;
            ////筛选后的总页数
            //pageCount = (Math.Ceiling(totalCount.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt();
            //permissions = permissions.OrderByDescending(d => d.Id).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();
            #endregion



            permissions = await _permissionServices.QueryPage(a => a.IsDeleted != true && (a.Name != null && a.Name.Contains(key)), page, intPageSize, " Id desc ");


            #region 单独处理

            var apis = await _moduleServices.Query(d => d.IsDeleted == false);

            var permissionsView = permissions.data;

            foreach (var item in permissionsView)
            {
                List <int> pidarr = new List <int>();
                pidarr.Add(item.Pid);
                if (item.Pid > 0)
                {
                    pidarr.Add(0);
                }
                var parent = permissionsView.FirstOrDefault(d => d.Id == item.Pid);

                while (parent != null)
                {
                    pidarr.Add(parent.Id);
                    parent = permissionsView.FirstOrDefault(d => d.Id == parent.Pid);
                }


                item.PidArr = pidarr.OrderBy(d => d).Distinct().ToList();
                foreach (var pid in item.PidArr)
                {
                    var per = permissionsView.FirstOrDefault(d => d.Id == pid);
                    item.PnameArr.Add((per != null ? per.Name : "根节点") + "/");
                    //var par = Permissions.Where(d => d.Pid == item.Id ).ToList();
                    //item.PCodeArr.Add((per != null ? $"/{per.Code}/{item.Code}" : ""));
                    //if (par.Count == 0 && item.Pid == 0)
                    //{
                    //    item.PCodeArr.Add($"/{item.Code}");
                    //}
                }

                item.MName = apis.FirstOrDefault(d => d.Id == item.Mid)?.LinkUrl;
            }

            permissions.data = permissionsView;

            #endregion


            return(new MessageModel <PageModel <Permission> >()
            {
                msg = "获取成功",
                success = permissions.dataCount >= 0,
                response = permissions
            });
        }