Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nul800sebastiaan/9189c212e4237882d520 to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/9189c212e4237882d520 to your computer and use it in GitHub Desktop.
PopulatePaging
private void PopulatePaging(Stream stream)
{
const int pageSize = 5;
var skipItems = (pageSize * stream.Page) - pageSize;
var posts = stream.Content.Children.ToList();
stream.TotalPages = Convert.ToInt32(Math.Ceiling((double)posts.Count() / pageSize));
stream.PreviousPage = stream.Page - 1;
stream.NextPage = stream.Page + 1;
stream.IsFirstPage = stream.Page <= 1;
stream.IsLastPage = stream.Page >= stream.TotalPages;
stream.StatusUpdates = posts.OrderByDescending(x => x.CreateDate).Skip(skipItems).Take(pageSize);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment