Example #1
0
 public async Task <List <CarCategoryDto> > Search(CarCategorySearch search)
 {
     if (string.IsNullOrWhiteSpace(search.Name) && !search.Fee.HasValue)
     {
         return(_mapper.Map <List <CarCategory>, List <CarCategoryDto> >(await _repository.GetAllAsync()));
     }
     return(_mapper.Map <List <CarCategory>, List <CarCategoryDto> >(await _repository.Search(search)));
 }
        public async Task <List <CarCategory> > Search(CarCategorySearch search)
        {
            var query = _dbContext.CarCategories.AsNoTracking().AsQueryable();

            if (!string.IsNullOrWhiteSpace(search.Name))
            {
                query = query.Where(cc => cc.Name.Contains(search.Name, StringComparison.InvariantCultureIgnoreCase));
            }
            if (search.Fee.HasValue)
            {
                query = query.Where(cc => cc.DailyFee == search.Fee.Value);
            }
            return(await query.OrderBy(cc => cc.DailyFee).ToListAsync());
        }