예제 #1
0
        private static int CalcSkip(IPaginationConditions paginationConditions)
        {
            var page     = GetPageValue(paginationConditions);
            var pageSize = GetPageSizeValue(paginationConditions);

            return(pageSize * (page - 1));
        }
예제 #2
0
        public static IPagination <TEntity> GetPagination <TEntity>(this Repository repo,
                                                                    IPaginationConditions paginationConditions,
                                                                    string sql,
                                                                    Dictionary <string, object> param = null)
            where TEntity : class
        {
            var allItems = repo.Query <TEntity>(sql, param);
            var items    = repo.PaginationQuery <TEntity>(allItems, CalcSkip(paginationConditions), GetPageSizeValue(paginationConditions));
            var count    = allItems.Count();

            var result = CreatePagination(paginationConditions, count, items);

            return(result);
        }
예제 #3
0
        private static IPagination <TEntity> CreatePagination <TEntity>(IPaginationConditions paginationConditions, int count, IEnumerable <TEntity> items)
            where TEntity : class
        {
            var page     = GetPageValue(paginationConditions);
            var pageSize = GetPageSizeValue(paginationConditions);
            var result   = new Pagination <TEntity>
            {
                Page     = page,
                PageSize = pageSize,
                MaxPage  = (count / pageSize) + ((count % pageSize == 0) ? 0 : 1),
                Items    = items
            };

            return(result);
        }
예제 #4
0
        private static int GetPageSizeValue(IPaginationConditions paginationConditions)
        {
            var pageSize = paginationConditions.PageSize.HasValue ? paginationConditions.PageSize.Value : DefaultPageSize;

            return(pageSize);
        }