public IPagedResult <Article> GetList(QueryArticleDto dto) { Expression <Func <Article, bool> > expression = null; if (!string.IsNullOrEmpty(dto.Keyword)) { expression = e => e.Title.Contains(dto.Keyword); } if (dto.CategoryId.HasValue) { Expression <Func <Article, bool> > exp = e => e.CategoryId == dto.CategoryId.Value; if (expression == null) { expression = exp; } else { expression = LambdaExpression.Lambda <Func <Article, bool> >(LambdaExpression.And(expression, exp)); } } if (dto.ArticleId.HasValue) { expression = e => e.Id == dto.ArticleId.Value; } var totalCount = _articleRepository.Count(expression); var query = _articleRepository.GetAll(expression); return(new PagedResultDto <Article>(totalCount, query.ToList())); }
public async Task <ArticleDetailDto> Handle(QueryArticleDto request, CancellationToken cancellationToken) { return(await GetAsync(request.Id)); }