Пример #1
0
        public static async Task <IssuesPagedList> CreateAsync(
            IQueryable <GeminiIssueEntity> source,
            IssuesQueryParameters issuesQueryParameters,
            CancellationToken token)
        {
            var count = source.Count();
            var requestedIssuePagination = MetaIssuePagination.ParsePagination(issuesQueryParameters);
            int pageNumber = 0;

            List <GeminiIssueEntity> items;

            if (requestedIssuePagination != null)
            {
                pageNumber = Math.Max(1, requestedIssuePagination.PageNumber);
                items      = await GetPageAsync(source, issuesQueryParameters.PageSize, pageNumber, token).ConfigureAwait(false);
            }
            else
            {
                items = await source.Take(issuesQueryParameters.PageSize).ToListAsync(token).ConfigureAwait(false);
            }

            var meta = new MetaIssuePagination
            {
                PageNumber = pageNumber,
                PageSize   = issuesQueryParameters.PageSize,
                CheckSum   = CreateCheckSum(issuesQueryParameters)
            };

            return(new IssuesPagedList(items, count, meta));
        }
Пример #2
0
        public static string Create(MetaIssuePagination metaIssuePagination, int totalPages, PageDirection pageDirection)
        {
            var pageNumber = metaIssuePagination.PageNumber;

            if (pageDirection == PageDirection.Next)
            {
                if (metaIssuePagination.PageNumber >= totalPages)
                {
                    return(string.Empty);
                }

                pageNumber++;
            }
            else if (pageDirection == PageDirection.Previous)
            {
                if (metaIssuePagination.PageNumber < 1)
                {
                    return(string.Empty);
                }

                pageNumber--;
            }

            var meta = new MetaIssuePagination
            {
                CheckSum   = metaIssuePagination.CheckSum,
                PageNumber = pageNumber,
                PageSize   = metaIssuePagination.PageSize
            };

            var json = JsonSerializer.Serialize(meta);

            return(Base64Encode(json));
        }
Пример #3
0
        private static IssuePagination CreateIssuePagination(int count, MetaIssuePagination metaIssuePagination)
        {
            var totalPages = (int)Math.Ceiling(count / (double)metaIssuePagination.PageSize);

            var issuePagination = new IssuePagination
            {
                Count        = count,
                CurrentPage  = MetaIssuePagination.Create(metaIssuePagination, totalPages, PageDirection.Current),
                NextPage     = MetaIssuePagination.Create(metaIssuePagination, totalPages, PageDirection.Next),
                PreviousPage = MetaIssuePagination.Create(metaIssuePagination, totalPages, PageDirection.Previous),
                TotalPages   = totalPages
            };

            return(issuePagination);
        }
Пример #4
0
 IssuesPagedList(List <GeminiIssueEntity> items, int count, MetaIssuePagination metaIssuePagination)
 {
     IssuePagination = CreateIssuePagination(count, metaIssuePagination);
     AddRange(items);
 }