using System; using System.Collections.Generic; using System.Linq; namespace UserManagement.Helper { public class PagedList : List { public int CurrentPage { get; private set; } public int TotalPages { get; private set; } public int Skip { get; set; } public int PageSize { get; private set; } public int TotalCount { get; private set; } public bool HasPrevious { get { return (CurrentPage > 1); } } public bool HasNext { get { return (CurrentPage < TotalPages); } } public PagedList(List items, int count, int skip, int pageSize) { TotalCount = count; PageSize = pageSize; Skip = skip; TotalPages = (int)Math.Ceiling(count / (double)pageSize); AddRange(items); } public static PagedList Create(IQueryable source, int skip, int pageSize) { var count = source.Count(); var items = source.Skip(skip).Take(pageSize).ToList(); return new PagedList(items, count, skip, pageSize); } } }