コード例 #1
0
        public async Task <ActionResult <ArticleToReturnDto> > GetArticleByIdAsync([FromQuery] int id)
        {
            var spec    = new ArticlesSpecification(id);
            var article = await _articlesRepo.GetEntityWithSpec(spec);

            await SetTimeOut();

            var articleToReturn = _mapper.Map <Article, ArticleToReturnDto>(article);
            var comments        = articleToReturn.Comments.Where(z => z.ParentId == null).ToList();

            articleToReturn.Comments = comments;
            return(Ok(articleToReturn));
        }
コード例 #2
0
        public async Task <ActionResult <PagedList <ArticleToReturnDto> > > GetArticles([FromQuery] UserParams?userParams)
        {
            var spec       = new ArticlesSpecification(userParams);
            var totalItems = await _articlesRepo.CountAsync(spec);

            var article = await _articlesRepo.ListAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Article>, IReadOnlyList <ArticleToReturnDto> >(article);

            await SetTimeOut();

            return(Ok(new Pagination <ArticleToReturnDto>(userParams.PageIndex, userParams.PageSize, totalItems, data)));
        }