Skip to content

Commit

Permalink
Sorted out Pagination count
Browse files Browse the repository at this point in the history
  • Loading branch information
garywoodfine committed Apr 27, 2022
1 parent 253b378 commit ba0cebd
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/Paging/Paginate.cs
Expand Up @@ -30,27 +30,20 @@ internal Paginate(IEnumerable<T> source, int index, int size, int from)
if (from > index)
throw new ArgumentException($"indexFrom: {from} > pageIndex: {index}, must indexFrom <= pageIndex");

if (source is IQueryable<T> querable)
if (source is IQueryable<T> queryable)
{
Index = index;
Size = size;
From = from;
Count = querable.Count();
Pages = (int) Math.Ceiling(Count / (double) Size);

Items = querable.Skip((Index - From) * Size).Take(Size).ToList();
Count = queryable.Count();
Items = queryable.Skip((Index - From) * Size).Take(Size).ToList();
}
else
{
Index = index;
Size = size;
From = from;

Count = enumerable.Count();
Pages = (int) Math.Ceiling(Count / (double) Size);

Count = enumerable.Length;
Items = enumerable.Skip((Index - From) * Size).Take(Size).ToList();
}
Index = index;
Size = size;
From = from;
Pages = (int) (Math.Ceiling(Count / (double) Size)) - 1;
}

internal Paginate()
Expand Down

0 comments on commit ba0cebd

Please sign in to comment.