45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System.Linq.Dynamic.Core;
|
|
|
|
namespace Complex.Application.Common
|
|
{
|
|
public static class Pagination
|
|
{
|
|
public static IQueryable<TSource> ToPagedByOrder<TSource>(this IQueryable<TSource> source,
|
|
CommonRequestDto commonRequest, out int rowsCount)
|
|
{
|
|
if (commonRequest.Length < 0)
|
|
commonRequest.Length = 20000;
|
|
if (commonRequest.Length == 0)
|
|
commonRequest.Length = 10;
|
|
|
|
rowsCount = source.Count();
|
|
|
|
if (commonRequest.sortDirection == SortDirection.desc)
|
|
commonRequest.SortField += " DESC";
|
|
|
|
source = source.OrderBy(commonRequest.SortField);
|
|
|
|
return source.Skip(commonRequest.Page * commonRequest.Length).Take(commonRequest.Length);
|
|
}
|
|
public static IQueryable<TSource> ToPaged<TSource>(this IQueryable<TSource> source, int page, int pageSize, out int rowsCount)
|
|
{
|
|
if (pageSize == -1)
|
|
pageSize = 20000;
|
|
if (pageSize == 0)
|
|
pageSize = 10;
|
|
|
|
rowsCount = source.Count();
|
|
return source.Skip(page * pageSize).Take(pageSize);
|
|
}
|
|
public static IQueryable<TSource> ToPaged<TSource>(this IQueryable<TSource> source, int page, int pageSize)
|
|
{
|
|
if (pageSize == -1)
|
|
pageSize = 20000;
|
|
if (pageSize == 0)
|
|
pageSize = 10;
|
|
|
|
return source.Skip(page * pageSize).Take(pageSize);
|
|
}
|
|
}
|
|
}
|