コード例 #1
0
        public async Task <IActionResult> Article(int page, string searchTerm)
        {
            var serviceModel = await this.searchService
                               .GetArticles(searchTerm, ArticlesPerPage, (page - 1) *ArticlesPerPage);

            var pagesCount = (int)Math.Ceiling(serviceModel.ArticlesCount / (decimal)ArticlesPerPage);

            var viewModel = new ArticlePaginationViewModel
            {
                Articles    = serviceModel.Articles.Select(a => AutoMapperConfig.MapperInstance.Map <BriefArticleInfoViewModel>(a)).ToList(),
                PagesCount  = pagesCount == 0 ? 1 : pagesCount,
                CurrentPage = page,
            };

            return(this.View(viewModel));
        }
コード例 #2
0
        public async Task <IActionResult> All(int page = 1)
        {
            var serviceModel = this.articleService
                               .GetAllPagination(ArticlesPerPage, (page - 1) * ArticlesPerPage);

            var pagesCount = (int)Math.Ceiling(this.articleService.GetAll().Count() / (decimal)ArticlesPerPage);
            var viewModel  = new ArticlePaginationViewModel()
            {
                Articles = (await serviceModel.ToListAsync())
                           .Select(a => AutoMapperConfig.MapperInstance.Map <BriefArticleInfoViewModel>(a))
                           .ToList(),
                PagesCount  = pagesCount == 0 ? 1 : pagesCount,
                CurrentPage = page,
            };

            return(this.View(viewModel));
        }