Ejemplo n.º 1
0
        public ActionResult ArticlesTable()
        {
            var articles   = _repo.Read().ToList();
            var viewModels = articles.Select(a => _mapper.MapToViewModel(a)).ToList();

            return(PartialView("ArticlesTable", viewModels));
        }
Ejemplo n.º 2
0
        public ActionResult Index(DateTime?monthFilter = null)
        {
            var articles = _repo.Read().Where(a => monthFilter == null
                                              ||
                                              (a.DatePublished.Month == monthFilter.Value.Month &&
                                               a.DatePublished.Year == monthFilter.Value.Year))
                           .OrderByDescending(a => a.DatePublished)
                           .ToList();

            var allArticles             = _repo.Read().ToList();
            var publicationMonths       = allArticles.Select(a => a.DatePublished.FirstDayOfMonth()).Distinct().OrderByDescending(m => m);
            var publicationMonthsByYear = publicationMonths.GroupBy(m => m.Year).ToList();

            var viewModel = new ViewArticlesViewModel
            {
                Articles = articles.Select(a => _mapper.MapToViewModel(a)).ToList(),
                PublicationMonthsByYear = publicationMonthsByYear
            };

            return(View(viewModel));
        }