public async Task <IActionResult> Index(CarTransportationSearchViewModel search) { var model = await _carTransportRepository .GetAllCars(search, this.CurrentPage, this.PageSize); this.PageCount = model.Item1; ViewBag.SearchModel = search; return(View(model.Item2)); }
///TODO Use Generic Grid View public async Task <Tuple <int, List <CarsTransportaionsFullDto> > > GetAllCars(CarTransportationSearchViewModel model, int skip, int take) { var query = TableNoTracking.Where(a => !a.IsDeleted).ProjectTo <CarsTransportaionsFullDto>(); query = query.WhereIf(!string.IsNullOrEmpty(model.CarName), a => a.CarName.Contains(model.CarName)); query = query.WhereIf(!string.IsNullOrEmpty(model.CarModel), a => a.CarModel.Contains(model.CarModel)); query = query.WhereIf(!string.IsNullOrEmpty(model.MotorSerial), a => a.MotorSerial.Contains(model.MotorSerial)); query = query.WhereIf(!string.IsNullOrEmpty(model.Plaque), a => a.Plaque.Contains(model.Plaque)); query = query.WhereIf(model.TransportSize != null, a => a.TransportSize == model.TransportSize); int Count = query.Count(); query = query.OrderByDescending(x => x.Id); if (skip != -1) { query = query.Skip((skip - 1) * take); } if (take != -1) { query = query.Take(take); } return(new Tuple <int, List <CarsTransportaionsFullDto> >(Count, await query.ToListAsync())); }