public async Task <IActionResult> Index(TariffSearchViewModel search) { var model = await _tariffRepository .GetAllTariff(search, this.CurrentPage, this.PageSize); this.PageCount = model.Item1; this.TotalNumber = model.Item1; ViewBag.SearchModel = search; ViewBag.Count = model.Item2.Count(); return(View(model.Item2)); }
public async Task <Tuple <int, List <TransportationTariffFullDto> > > GetAllTariff(TariffSearchViewModel model, int skip, int take) { var query = TableNoTracking.Include(a => a.CarTransport).Where(a => !a.IsDeleted).ProjectTo <TransportationTariffFullDto>(); query = query.WhereIf(!string.IsNullOrEmpty(model.CarName), a => a.CarTransportCarName.Contains(model.CarName)); query = query.WhereIf(model.TehranAreasFrom != null, a => a.TehranAreasFrom == model.TehranAreasFrom); query = query.WhereIf(model.TehranAreasTO != null, a => a.TehranAreasTO == model.TehranAreasTO); query = query.WhereIf(model.ProductSizeTo != null, a => a.ProductSizeTo == model.ProductSizeTo); query = query.WhereIf(model.ProductSizeFrom != null, a => a.ProductSizeFrom == model.ProductSizeFrom); query = query.WhereIf(model.Tariff != null, a => a.Tariff == model.Tariff); 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 <TransportationTariffFullDto> >(Count, await query.ToListAsync())); }