public async Task <IActionResult> OnGetLoadArticleAsync() { var queryInput = new QueryAriticelInputDto(); queryInput.FetchFromOther(Query.ToDto()); queryInput.OnlyPublish = false; queryInput.WithTags = true; queryInput.WithCategory = true; var result = (await articleService.GetArticleByPageAsync(queryInput)).ToBootStrapQueryResultModel(); return(new JsonResult(result)); }
public async Task <PagedResultDto <ArticleDto> > GetArticleByPageAsync(QueryAriticelInputDto pageQuery) { var query = _articleRep.GetAll(); if (pageQuery.OnlyPublish) { query = query.Where(o => o.IsPublish == true); } if (pageQuery.WithTags) { query = query.Include(o => o.ArticleTags); } if (pageQuery.WithCategory) { query = query.Include(o => o.Category); } var resultList = await query .OrderBy(pageQuery.Sorting ?? $"{nameof(Article.PostDate)} DESC") .Skip(pageQuery.SkipCount) .Take(pageQuery.MaxResultCount) .ToListAsync(); List <ArticleDto> result; if (pageQuery.WithTags) { result = resultList.Select(o => { var tmp = o.MapTo <ArticleDto>(); tmp.Tags = o.ArticleTags.Select(at => at.Tag.MapTo <TagDto>()).ToList(); return(tmp); }).ToList(); } else { result = resultList.MapTo <List <ArticleDto> >(); } var total = await query.CountAsync(); return(new PagedResultDto <ArticleDto>(total, result)); }