This commit is contained in:
2026-03-25 14:55:34 +08:00
commit 2c44b3a4b2
131 changed files with 7453 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
namespace StopShopping.Services.Models.Resp;
public class PagedResult<T>
{
public int PageCount { get; set; }
public int PageSize { get; set; }
public int PageIndex { get; set; }
public List<T> Data { get; set; } = [];
}
public static class PagedQueryExtensions
{
public static async Task<PagedResult<T>> ToPagedAsync<T>(this IAsyncEnumerable<T> query
, int pageIndex = 1
, int pageSize = 20)
{
PagedResult<T> 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;
}
}