MCPcopy Create free account
hub / github.com/TryCatchLearn/Overflow / ToPaginatedListAsync

Method ToPaginatedListAsync

Common/Pagination.cs:24–44  ·  view source on GitHub ↗
(this IQueryable<T> source,
        PaginationRequest request)

Source from the content-addressed store, hash-verified

22public static class PaginationExtensions
23{
24 public static async Task<PaginationResult<T>> ToPaginatedListAsync<T>(this IQueryable<T> source,
25 PaginationRequest request)
26 {
27 var total = await source.CountAsync();
28
29 var page = request.SafePage <= 0 ? 1 : request.SafePage;
30 var pageSize = request.CappedPageSize;
31
32 var items = await source
33 .Skip((page -1) * pageSize)
34 .Take(pageSize)
35 .ToListAsync();
36
37 return new PaginationResult<T>
38 {
39 Items = items,
40 TotalCount = total,
41 Page = page,
42 PageSize = pageSize
43 };
44 }
45}

Callers 1

GetQuestionsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected