public ActionResult Index(int page = 1) { ArticlesViewModel viewModel = new ArticlesViewModel { Articles = this.articleRepository.Articles.Where(b => b != null).OrderByDescending( b => b.Modified).Skip((page - 1) * this.pageSize).Take(this.pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = this.pageSize, TotalItems = this.articleRepository.Articles.Count() } }; ViewBag.Title = "Recent Articles"; return this.View(viewModel); }
/// <summary> /// Lists the specified archive. /// </summary> /// <param name="archive">The archive.</param> /// <param name="page">The page.</param> /// <returns>Page Content</returns> public ActionResult List(string archive = "", int page = 1) { DateTime dateRangeMin = archive != string.Empty ? DateTime.Parse(archive) : DateTime.MinValue; DateTime dateRangeMax = archive != string.Empty ? dateRangeMin.AddMonths(1) : DateTime.MaxValue; var viewModel = new ArticlesViewModel { Articles = this.articleRepository.Articles .Where(a => archive == null || (a.Modified.CompareTo(dateRangeMin) >= 0 && a.Modified.CompareTo(dateRangeMax) < 0)) .OrderByDescending(p => p.Modified) .Skip((page - 1) * this.pageSize) .Take(this.pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = this.pageSize, TotalItems = archive == string.Empty ? this.articleRepository.Articles.Count() : this.articleRepository.Articles.Count(a => (a.Modified.CompareTo(dateRangeMin) >= 0 && a.Modified.CompareTo(dateRangeMax) < 0)) }, CurrentArchive = archive }; if (!string.IsNullOrEmpty(viewModel.CurrentArchive)) { ViewBag.Message = viewModel.CurrentArchive; } else { ViewBag.Message = null; } return this.View(viewModel); }