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)); }
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)); }