BotSharp/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs

54 lines
1 KiB
C#
Raw Normal View History

2024-08-22 11:54:50 +00:00
using BotSharp.Abstraction.Infrastructures;
2023-12-04 23:42:46 +00:00
namespace BotSharp.Abstraction.Utilities;
2024-08-22 11:54:50 +00:00
public class Pagination : ICacheKey
2023-12-04 23:42:46 +00:00
{
2024-02-05 00:38:00 +00:00
private int _page;
private int _size;
2024-02-05 00:38:00 +00:00
public int Page
{
get { return _page > 0 ? _page : 1; }
set { _page = value; }
}
public int Size
{
2024-05-29 02:36:27 +00:00
get
2024-02-05 00:38:00 +00:00
{
2024-05-30 08:49:55 +00:00
return _size > 0 ? _size : 1;
}
set
{
_size = value;
}
2024-02-05 00:38:00 +00:00
}
2024-05-13 21:00:39 +00:00
/// <summary>
/// Sort by field
/// </summary>
public string? Sort { get; set; }
2024-05-13 21:09:53 +00:00
/// <summary>
/// Sort order: asc or desc
/// </summary>
public string Order { get; set; } = "asc";
2024-02-05 00:38:00 +00:00
public int Offset
{
get { return (Page - 1) * Size; }
}
2024-06-16 04:41:42 +00:00
public bool ReturnTotal { get; set; } = true;
2024-08-22 11:54:50 +00:00
public string GetCacheKey()
2024-08-23 02:09:06 +00:00
=> $"{nameof(Pagination)}_{_page}_{_size}_{Sort}_{Order}";
2023-12-04 23:42:46 +00:00
}
public class PagedItems<T>
{
public int Count { get; set; }
2024-02-04 05:42:13 +00:00
public IEnumerable<T> Items { get; set; } = new List<T>();
2023-12-04 23:42:46 +00:00
}