first commit
This commit is contained in:
37
MyNewProjectName.Contracts/Common/PagedList.cs
Normal file
37
MyNewProjectName.Contracts/Common/PagedList.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace MyNewProjectName.Contracts.Common
|
||||
{
|
||||
// PagedList model to support pagination in API responses
|
||||
public class PagedList<T>
|
||||
{
|
||||
// Items in the current page
|
||||
public List<T> Items { get; set; } = new List<T>();
|
||||
|
||||
// Total count of items across all pages
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
// Current page number
|
||||
public int PageNumber { get; set; }
|
||||
|
||||
// Page size (items per page)
|
||||
public int PageSize { get; set; }
|
||||
|
||||
// Total number of pages
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
|
||||
// Flag indicating if there is a previous page
|
||||
public bool HasPreviousPage => PageNumber > 1;
|
||||
|
||||
// Flag indicating if there is a next page
|
||||
public bool HasNextPage => PageNumber < TotalPages;
|
||||
public PagedList(List<T> items, int totalCount, int pageNumber, int pageSize)
|
||||
{
|
||||
Items = items;
|
||||
TotalCount = totalCount;
|
||||
PageNumber = pageNumber;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
public PagedList() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user