private void FillFilterExpression(RobotModelFilterParams filterParams) { Expression <Func <RobotModel, bool> > predicate = PredicateBuilder.New <RobotModel>(true); if (!string.IsNullOrEmpty(filterParams.Term)) { predicate = predicate.Extend(t => t.Name.Contains(filterParams.Term)); } filterParams.Expression = predicate; }
public async Task <CollectionResult <RobotModel> > GetModelsByFilterParamsAsync(RobotModelFilterParams filterParams, CancellationToken ct = default) { IQueryable <RobotModel> query = DbContext.RobotModels .Include(m => m.Company) .Include(m => m.Type) .AsQueryable(); FillFilterExpression(filterParams); query = query.Where(filterParams.Expression); int totalCount = query.Count(); List <RobotModel> items = await query .OrderBy(x => x.Name) .WithPagination(filterParams.Skip, filterParams.Take) .AsNoTracking() .ToListAsync(ct); CollectionResult <RobotModel> result = new CollectionResult <RobotModel> { Collection = items, TotalCount = totalCount }; return(result); }