Example #1
0
        public async Task <IActionResult> NewsletterAsync(int?page)
        {
            int categoryId = 21;

            var vm = new ArticlePageVM
            {
                PageIndex         = page ?? 1,
                PageSize          = 12,
                RecommendArticles = await _context.Articles.Where(d => d.Recommend && d.Active == true && d.CategoryId == categoryId)
                                    .OrderByDescending(d => d.Pubdate).ThenByDescending(d => d.Id)
                                    .ProjectTo <ArticleVM>(_mapper.ConfigurationProvider).ToListAsync()
            };

            var query = _context.Articles.Where(d => d.Active == true && d.CategoryId == categoryId).AsNoTracking();


            vm.TotalCount = await query.CountAsync();

            var articles = await query.OrderByDescending(d => d.Pubdate).ThenByDescending(d => d.Id).ProjectTo <ArticleVM>(_mapper.ConfigurationProvider)
                           .Skip((vm.PageIndex - 1) * vm.PageSize).Take(vm.PageSize)
                           .ToListAsync();

            vm.Articles = new StaticPagedList <ArticleVM>(articles, vm.PageIndex, vm.PageSize, vm.TotalCount);


            var url = Request.Path.ToString();

            ViewData["PageMeta"] = await _context.PageMetas.FirstOrDefaultAsync(d => d.ObjectId == url && d.ModuleType == (short)ModuleType.MENU);

            ViewData["Page"] = await _context.Pages.FirstOrDefaultAsync(d => d.SeoName == "newsletter");

            return(View(vm));
        }
Example #2
0
        public async Task <IActionResult> List(int?page)
        {
            var vm = new ArticlePageVM()
            {
                //Categories = await _context.ArticleCategories.Where(d => d.Active == true)
                //    .OrderByDescending(d => d.Importance)
                //    .ProjectTo<ArticleCategoryVM>(_mapper.ConfigurationProvider).ToListAsync(),
                PageIndex = page == null || page <= 0 ? 1 : page.Value
            };
            var pageSize = 20;

            var query = _context.Articles.Where(d => d.Active == true).AsNoTracking();


            vm.TotalCount = await query.CountAsync();

            var articles = await query.OrderByDescending(d => d.Id).ProjectTo <ArticleVM>(_mapper.ConfigurationProvider)
                           .Skip((vm.PageIndex - 1) * pageSize).Take(pageSize)
                           .ToListAsync();

            vm.Articles = new StaticPagedList <ArticleVM>(articles, vm.PageIndex, pageSize, vm.TotalCount);

            return(View(vm));
        }