Major update
This commit is contained in:
38
games/Helpers/PagedList.cs
Normal file
38
games/Helpers/PagedList.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using Games.Entities;
|
||||
|
||||
namespace Games.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);
|
||||
}
|
||||
|
||||
internal static PagedList<Game> ToPagedList(List<Game> games)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user