예제 #1
0
        public static void AddPaginationResponseHeaders(
            this HttpContext httpContext,
            int recordCount,
            int pageSize,
            int pageIndex
            )
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException(nameof(httpContext));
            }

            // calculate total number of pages
            int totalPages = (int)Math.Ceiling(recordCount / (double)pageSize);

            // also work out if there are previous or next pages
            bool hasPrevious = pageIndex > 1;
            bool hasNext     = pageIndex < totalPages;

            var paginationHeader = new PaginationResponseHeader
            {
                TotalCount      = recordCount,
                PageIndex       = pageIndex,
                PageSize        = pageSize,
                TotalPages      = totalPages,
                HasPreviousPage = hasPrevious,
                HasNextPage     = hasNext
            };

            httpContext.Response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader));
        }
예제 #2
0
 public static void AddPagination(this HttpResponse response, PaginationResponseHeader pagination)
 {
     response.Headers.Add("Pagination", JsonConvert.SerializeObject(pagination));
     response.Headers.Add("access-control-expose-headers", "Pagination");
 }