Created
August 18, 2014 12:24
-
-
Save ctrlShiftBryan/f2f1133b789e726bf7eb to your computer and use it in GitHub Desktop.
PageInfo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FakePage<T> : List<T> , IPagedList<T> | |
| { | |
| public FakePage(int page, int pageSize, int totalRecords, IEnumerable<T> collection ) : base(collection) | |
| { | |
| this.PageCount = (totalRecords + pageSize -1 ) / pageSize; | |
| this.TotalItemCount = totalRecords; | |
| this.PageNumber = page; | |
| this.PageSize = pageSize; | |
| this.HasPreviousPage = page > 1; | |
| this.HasNextPage = page != this.PageCount; | |
| this.IsFirstPage = page == 1; | |
| this.IsLastPage = page == this.PageCount; | |
| this.FirstItemOnPage = ((page - 1) * pageSize) + 1; | |
| this.LastItemOnPage = this.IsLastPage ? totalRecords : FirstItemOnPage + pageSize; | |
| } | |
| public int PageCount { get; private set; } | |
| public int TotalItemCount { get; private set; } | |
| public int PageNumber { get; private set; } | |
| public int PageSize { get; private set; } | |
| public bool HasPreviousPage { get; private set; } | |
| public bool HasNextPage { get; private set; } | |
| public bool IsFirstPage { get; private set; } | |
| public bool IsLastPage { get; private set; } | |
| public int FirstItemOnPage { get; private set; } | |
| public int LastItemOnPage { get; private set; } | |
| public IPagedList GetMetaData() | |
| { | |
| return this; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment