First commit. Include junk from template to remove
This commit is contained in:
29
src/Application/Common/Models/PaginatedList.cs
Normal file
29
src/Application/Common/Models/PaginatedList.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace Hutopy.Application.Common.Models;
|
||||
|
||||
public class PaginatedList<T>
|
||||
{
|
||||
public IReadOnlyCollection<T> Items { get; }
|
||||
public int PageNumber { get; }
|
||||
public int TotalPages { get; }
|
||||
public int TotalCount { get; }
|
||||
|
||||
public PaginatedList(IReadOnlyCollection<T> items, int count, int pageNumber, int pageSize)
|
||||
{
|
||||
PageNumber = pageNumber;
|
||||
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
|
||||
TotalCount = count;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
public bool HasPreviousPage => PageNumber > 1;
|
||||
|
||||
public bool HasNextPage => PageNumber < TotalPages;
|
||||
|
||||
public static async Task<PaginatedList<T>> CreateAsync(IQueryable<T> source, int pageNumber, int pageSize)
|
||||
{
|
||||
var count = await source.CountAsync();
|
||||
var items = await source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync();
|
||||
|
||||
return new PaginatedList<T>(items, count, pageNumber, pageSize);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user