Beispiel #1
0
 public async Task <List <CarModelDto> > Search(CarModelSearch search)
 {
     if (string.IsNullOrWhiteSpace(search.Name) && !search.BrandId.HasValue && !search.CategoryId.HasValue)
     {
         return(_mapper.Map <List <CarModel>, List <CarModelDto> >(await _repository.GetAllAsync()));
     }
     return(_mapper.Map <List <CarModel>, List <CarModelDto> >(await _repository.Search(search)));
 }
        public async Task <List <CarModel> > Search(CarModelSearch search)
        {
            var query = _dbContext.CarModels.AsNoTracking().AsQueryable();

            if (!string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(cm => cm.Title.Contains(search.Name, StringComparison.InvariantCultureIgnoreCase));
            }
            if (search.BrandId.HasValue)
            {
                query = query.Where(cm => cm.BrandId == search.BrandId.Value);
            }
            if (search.CategoryId.HasValue)
            {
                query = query.Where(cm => cm.CategoryId == search.CategoryId.Value);
            }
            return(await query.OrderBy(cm => cm.Title).ToListAsync());
        }