Advertisement
Guest User

stronicowanie

a guest
Mar 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class PaginatedList<T> : List<T>
  2. {
  3. public int PageIndex { get; private set; }
  4. public int TotalPages { get; private set; }
  5.  
  6. public PaginatedList(List<T> items, int count, int pageIndex, int pageSize)
  7. {
  8. PageIndex = pageIndex;
  9. TotalPages = (int)Math.Ceiling(count / (double)pageSize);
  10.  
  11. AddRange(items);
  12. }
  13.  
  14.  
  15. public bool HasPreviousPage
  16. {
  17. get
  18. {
  19. return (PageIndex > 1);
  20. }
  21. }
  22.  
  23. public bool HasNextPage
  24. {
  25. get
  26. {
  27. return (PageIndex < TotalPages);
  28. }
  29. }
  30.  
  31. public static async Task<PaginatedList<T>> CreateAsync(IQueryable<T> source, int pageIndex, int pageSize)
  32. {
  33. var count = await source.CountAsync();
  34. var items = await source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();
  35. return new PaginatedList<T>(items, count, pageIndex, pageSize);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement