namespace StopShopping.Services.Models.Resp; public class PagedResult { public int PageCount { get; set; } public int PageSize { get; set; } public int PageIndex { get; set; } public List Data { get; set; } = []; } public static class PagedQueryExtensions { public static async Task> ToPagedAsync(this IAsyncEnumerable query , int pageIndex = 1 , int pageSize = 20) { PagedResult result = new() { PageSize = pageSize, PageIndex = pageIndex }; var total = await query.CountAsync(); result.PageCount = (int)Math.Ceiling(total / (decimal)result.PageSize); result.Data = await query .Skip((result.PageIndex - 1) * result.PageSize) .Take(result.PageSize) .ToListAsync(); return result; } }