public async Task <IActionResult> Index(CarsInventoryBindingModel model) { var cookie = this.HttpContext.Request.Cookies; var sortDirectionKey = WebConstants.CookieUserUsedCarsSortDirectionKey; var sortDirection = this.cookiesService.GetValueOrDefault <SortStrategyDirection>(cookie, sortDirectionKey); var sortTypeKey = WebConstants.CookieUserUsedCarsSortTypeKey; var sortType = this.cookiesService.GetValueOrDefault <UsedCarSortStrategyType>(cookie, sortTypeKey); var sortStrategy = UsedCarSortStrategyFactory.GetStrategy <UsedCar>(sortType, sortDirection); var priceRanges = ParameterParser.ParsePriceRange(model.PriceRange); var filterStrategies = CarFilterStrategyFactory .GetStrategies(model.Year, priceRanges[0], priceRanges[1], model.Series); var filteredCars = this.carsService .GetFiltered <UsedCar>(filterStrategies.ToArray()); var sortedAndFilteredCars = sortStrategy.Sort(filteredCars); var filterMultipleStrategy = CarMultipleFilterStrategyFactory.GetStrategy(model.ModelTypes); var filteredByMultipleCars = filterMultipleStrategy.Filter(sortedAndFilteredCars); var currentPageViewModels = await(await this.carTestDriveService .GetCarTestDriveModelAsync <CarConciseTestDriveServiceModel>(filteredByMultipleCars, this.User, model.PageNumber)) .To <CarInventoryConciseViewModel>() .ToArrayAsync(); var key = KeyGenerator.Generate( WebConstants.CacheUsedInventoryPrepend, model.ModelTypes, model.PageNumber.ToString(), model.PriceRange, model.Series, model.Year); CarsFilterViewModel filterViewModel; var cachedModel = await this.cacheService.GetOrDefaultAsync <CarsFilterViewModel>(key); if (cachedModel != null) { filterViewModel = cachedModel; } else { var filterServiceModel = await this.carsFilterTypesService .GetCarFilterModelAsync(sortedAndFilteredCars, filteredByMultipleCars); filterViewModel = Mapper.Map <CarsFilterViewModel>(filterServiceModel); } var viewModel = new CarsInventoryViewModel() { SortStrategyType = sortType, SortStrategyDirection = sortDirection, Cars = currentPageViewModels, CurrentPage = model.PageNumber, FilterModel = filterViewModel, TotalPagesCount = await PaginationHelper.CountTotalPagesCountAsync(filteredByMultipleCars), TotalCarsCount = await filteredByMultipleCars.CountAsync() }; FilterTypeHelper.SelectFilterTypes(filterViewModel.Years, model.Year); FilterTypeHelper.SelectFilterTypes(filterViewModel.Series, model.Series); FilterTypeHelper.SelectFilterTypes(filterViewModel.ModelTypes, model.ModelTypes.ToArray()); FilterTypeHelper.SelectFilterTypes(filterViewModel.Prices, model.PriceRange); _ = this.cacheService.AddInfinityCacheAsync(filterViewModel, key, WebConstants.CacheCarsType); return(View(viewModel)); }
public IActionResult Search(CarType inventory, CarsInventoryBindingModel model) { var controllerName = CarType.NewCar == inventory ? "NewInventory" : "UsedInventory"; return(RedirectToAction("Index", controllerName, model)); }