Exemple #1
0
        public async Task <MessageModel <PageModel <sysUserInfo> > > Get(int page = 1, string key = "")
        {
            var data          = new MessageModel <PageModel <sysUserInfo> >();
            int intTotalCount = 50;
            int TotalCount    = 0;
            int PageCount     = 1;
            List <sysUserInfo> sysUserInfos = new List <sysUserInfo>();

            sysUserInfos = await _sysUserInfoServices.Query(a => a.tdIsDelete != true && a.uStatus >= 0);

            if (!string.IsNullOrEmpty(key))
            {
                sysUserInfos = sysUserInfos.Where(t => (t.uLoginName != null && t.uLoginName.Contains(key)) || (t.uRealName != null && t.uRealName.Contains(key))).ToList();
            }


            //筛选后的数据总数
            TotalCount = sysUserInfos.Count;
            //筛选后的总页数
            PageCount = (Math.Ceiling(TotalCount.ObjToDecimal() / intTotalCount.ObjToDecimal())).ObjToInt();

            sysUserInfos = sysUserInfos.OrderByDescending(d => d.uID).Skip((page - 1) * intTotalCount).Take(intTotalCount).ToList();

            foreach (var item in sysUserInfos)
            {
                if (item != null)
                {
                    item.RID = await _userRoleServices.GetRoleIdByUid(item.uID);

                    item.RoleName = await _roleServices.GetRoleNameByRid(item.RID);
                }
            }

            return(new MessageModel <PageModel <sysUserInfo> >()
            {
                msg = "获取成功",
                success = TotalCount >= 0,
                response = new PageModel <sysUserInfo>()
                {
                    page = page,
                    pageCount = PageCount,
                    dataCount = TotalCount,
                    data = sysUserInfos,
                }
            });
        }