using Exam.Share.Requests; using SqlSugar; namespace Exam.Repository.Sqlsugar.Extensions { public static class SqlSugarRepositoryExtensions { public static async Task<(int Total, List Items)> ToPagedListAsync(this ISugarQueryable query, int pageIndex, int pageSize, CancellationToken cancellationToken = default) where TEntity : class, new() { RefAsync total = 0; var items = await query.ToPageListAsync(pageIndex, pageSize, total); return (total.Value, items); } public static async Task<(int Total, List Items)> ToPagedListAsync(this ISugarQueryable query, PagedRequest dto, CancellationToken cancellationToken = default) where TEntity : class, new() { RefAsync total = 0; var items = await query.ToPageListAsync(dto.PageIndex, dto.PageSize, total); return (total.Value, items); } public static Task> ToFixedListAsync(this ISugarQueryable query, int queryIndex, int? queryCount = null, CancellationToken cancellationToken = default) where TEntity : class, new() { if (queryCount is null or 0) queryCount = 50; return query.Skip(queryIndex * queryCount.Value).Take(queryCount.Value).ToListAsync(cancellationToken); } } }