Exemplo n.º 1
0
        /// <summary>
        /// 获取Demo分页
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="SortField"></param>
        /// <param name="SortType"></param>
        /// <returns></returns>
        public async Task <PageResult <Demo> > GetDemoPageListAsync(int PageIndex, int PageSize, string SortField, string SortType)
        {
            var demoList  = new PageResult <Demo>();
            var demoModel = _demoRepository.GetAsIQuerable();
            var MaxPage   = demoModel.Count() == 0 ? demoModel.Count() / PageSize : (demoModel.Count() / PageSize) + 1;

            if (PageIndex > MaxPage)
            {
                PageIndex = MaxPage; //超过最大页数默认获取最后一页
            }
            demoList.PageIndex  = PageIndex;
            demoList.PageSize   = PageSize;
            demoList.TotalCount = demoModel.Count();
            if (demoModel.Any())
            {
                demoList.list = await PaginationHelper.SortingAndPaging(demoModel, SortField, SortType, PageIndex, PageSize).ToListAsync();
            }
            return(demoList);
        }