public ActionResult Index()
        {
            var snippets = this.Data.Snippets
               .All()
               .OrderByDescending(s => s.CreationDateTime)
               .Take(5)
               .Project()
               .To<SnippetViewModel>();

            var comments = this.Data.Comments
               .All()
               .OrderByDescending(c => c.CreationDateTime)
               .Take(5)
               .Project()
               .To<CommentViewModel>();

            var labels = this.Data.Labels
               .All()
               .OrderByDescending(l => l.Snippets.Count())
               .Take(5)
               .Project()
               .To<LabelViewModel>();

            var result = new HomeViewModel()
            {
                BestLabels = labels,
                LatestSnippets = snippets,
                LatestComments = comments
            };

            return View(result);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var topFiveSnippetsByAddion =
                this.Data.Snippets.All()
                    .OrderByDescending(s => s.CreatedAt)
                    .Take(TopFive)
                    .ProjectTo<SnippetViewModel>()
                    .ToList();

            var topFiveCommentsByDate =
                this.Data.Comments.All()
                    .OrderByDescending(c => c.CreatedAt)
                    .Take(TopFive)
                    .ProjectTo<CommentViewModel>()
                    .ToList();
            var topFiveLabelsBySnippetsCount =
                this.Data.Labels.All()
                    .OrderByDescending(l => l.Snippets.Count)
                    .Take(TopFive)
                    .ProjectTo<LabelViewModel>()
                    .ToList();
            var homeModel = new HomeViewModel
            {
                Snippets = topFiveSnippetsByAddion,
                Commnets = topFiveCommentsByDate,
                Labels = topFiveLabelsBySnippetsCount
            };
            return this.View(homeModel);
        }