public ActionResult Index(string category = null, string author = null, int year = 0, int month = 0, int page = 1)
{
var allPosts = _index.GetBlogPosts(category, author, year, month);
if (page < 1)
{
page = 1;
}
if ((page - 1)*PostsPerPage >= allPosts.Count && allPosts.Count > 0)
{
return new HttpNotFoundResult();
}
var posts = allPosts.OrderByDescending(x => x.PostedAt)
.Skip((page - 1) * PostsPerPage)
.Take(PostsPerPage).ToArray();
return View(new BlogPageViewModel(posts, _index.GetCategories(), _index.GetArchive(), _index.GetAuthors())
{
CurrentPage = page,
HasOlderPosts = allPosts.Count > page * PostsPerPage,
HasNewerPosts = page > 1,
Category = category,
Author = author,
Year = year,
Month = month
});
}