Major update
This commit is contained in:
32
divisions/Helpers/PagedList.cs
Normal file
32
divisions/Helpers/PagedList.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
namespace Divisions.Helpers
|
||||
{
|
||||
public class PagedList<T> : List<T>
|
||||
{
|
||||
public int CurrentPage { get; set; }
|
||||
public int PageSize { get; private set; }
|
||||
public int TotalCount { get; private set; }
|
||||
public int TotalPages { get; private set; }
|
||||
|
||||
public PagedList(List<T> items, int count, int pageNumber, int pageSize)
|
||||
{
|
||||
CurrentPage = pageNumber;
|
||||
PageSize = pageSize;
|
||||
TotalCount = count;
|
||||
TotalPages = (int)Math.Ceiling(count / (double)pageSize);
|
||||
|
||||
AddRange(items);
|
||||
}
|
||||
|
||||
public static PagedList<T> ToPagedList(List<T> source, int pageNumber, int pageSize)
|
||||
{
|
||||
var count = source.Count();
|
||||
var items = source.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToList();
|
||||
|
||||
return new PagedList<T>(items, count, pageNumber, pageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user