private Expression <Func <Fact, bool> > BuildPredicate(FactGetPagedRequest request) { var predicate = PredicateBuilder.True <Fact>(); if (!string.IsNullOrWhiteSpace(request.Search)) { predicate = predicate.And(x => x.Content.Contains(request.Search)); } if (!string.IsNullOrWhiteSpace(request.Tag)) { predicate = predicate.And(x => x.Tags.Select(t => t.Name).Contains(request.Tag)); } return(predicate); }
public override async Task <OperationResult <IPagedList <FactViewModel> > > Handle(FactGetPagedRequest request, CancellationToken cancellationToken) { var operation = OperationResult.CreateResult <IPagedList <FactViewModel> >(); var predicate = BuildPredicate(request); var items = await _unitOfWork.GetRepository <Fact>() .GetPagedListAsync( predicate: predicate, include: i => i.Include(x => x.Tags), orderBy: o => o.OrderByDescending(x => x.CreatedAt), pageIndex: request.PageIndex, pageSize: request.PageSize, cancellationToken: cancellationToken); var mapped = _mapper.Map <IPagedList <FactViewModel> >(items); operation.Result = mapped; operation.AddSuccess("Success"); return(operation); }