Files
deepdrft/DeepDrftModels/Models/PagedResult.cs
T

35 lines
1002 B
C#

namespace DeepDrftModels.Models;
public class PagedResult<T>
{
public IEnumerable<T> Items { get; set; } = new List<T>();
public int TotalCount { get; set; }
public int Page { get; set; }
public int PageSize { get; set; }
public int TotalPages => PageSize > 0 ? (int)Math.Ceiling((double)TotalCount / PageSize) : 0;
public bool HasNextPage => Page < TotalPages;
public bool HasPreviousPage => Page > 1;
public PagedResult()
{
}
public static PagedResult<T> From<TOther>(PagedResult<TOther> other, IEnumerable<T> items)
{
return new PagedResult<T>()
{
Items = items.ToList(),
Page = other.Page,
PageSize = other.PageSize,
TotalCount = other.TotalCount,
};
}
public PagedResult(IEnumerable<T> items, int totalCount, int page, int pageSize)
{
Items = items.ToList();
TotalCount = totalCount;
Page = page;
PageSize = pageSize;
}
}