public ActionResult Index() { var fiveLatestSnippets = this.Data.Snippets.All() .OrderByDescending(s => s.CreationTime) .ThenByDescending(s => s.Id) .Take(5); var fiveLatestComments = this.Data.Comments.All() .OrderByDescending(c => c.CreationTime) .ThenByDescending(c => c.Id) .Take(5); var fiveBestLabels = this.Data.Labels.All() .OrderByDescending(l => l.Snippets.Count) .ThenBy(l => l.Id) .Take(5); var model = new HomePageViewModel() { FiveLatestSnippets = Mapper.Map<IEnumerable<SnippetViewModel>>(fiveLatestSnippets), FiveLatestComments = Mapper.Map<IEnumerable<TopCommentViewModel>>(fiveLatestComments), FiveBestLabels = Mapper.Map<IEnumerable<LabelViewModel>>(fiveBestLabels) }; return this.View(model); }
public ActionResult Index() { var latestSnippets = this.Data.Snippets.All() .Include(s => s.Labels) .OrderByDescending(s => s.CreationDate) .Take(5); var latestComments = this.Data.Comments.All() .OrderByDescending(c => c.CreationDate) .Take(5); var topLabels = this.Data.Labels.All() .Include(c => c.Snippets) .OrderByDescending(l => l.Snippets.Count) .Take(5); var homeView = new HomePageViewModel() { Comments = Mapper.Map<IEnumerable<ConciseCommentViewModel>>(latestComments), Labels = Mapper.Map<IEnumerable<ConciseLabelViewModel>>(topLabels), Snippets = Mapper.Map<IEnumerable<ConciseSnippetViewModel>>(latestSnippets) }; return View(homeView); }