public static async Task <PagedResult <T> > PaginateAsync <T>(this IFindFluent <T, T> findFluent, int page = 0, int resultsPerPage = 20) { if (page < 0) { page = 0; } if (resultsPerPage <= 0) { resultsPerPage = 20; } var isEmpty = await findFluent.AnyAsync() == false; if (isEmpty) { return(PagedResult <T> .Empty); } var totalResults = await findFluent.CountDocumentsAsync(); var totalPages = (int)Math.Ceiling((decimal)totalResults / resultsPerPage); var data = await findFluent.Limit(page, resultsPerPage).ToListAsync(); return(PagedResult <T> .Create(data, page, resultsPerPage, totalPages, totalResults)); }
public static async Task <PagedResultFromStart <T> > PaginateFromStartAsync <T, TKey>(this IFindFluent <T, T> collection, int page = 1, int resultsPerPage = 10, long?totalResultsInCollection = 0) where T : IIdentifiable <TKey> { if (page <= 0) { page = 1; } if (resultsPerPage <= 0) { resultsPerPage = 10; } var isEmpty = await collection.AnyAsync() == false; if (isEmpty) { return(PagedResultFromStart <T> .Empty); } var totalResults = totalResultsInCollection;//await collection.CountAsync(); var totalPages = (int)Math.Ceiling((decimal)totalResults / resultsPerPage); var data = await collection.Limit(page, resultsPerPage).ToListAsync(); return(PagedResultFromStart <T> .Create(data, page, resultsPerPage, totalPages, totalResults ?? 0)); }