private void InitFilterData() { if (FilterCurrentData != null && FilterCurrentData.IsTypeInitialized) { return; } var valuePropertyBindingPath = GetValuePropertyBindingPath(AssignedDataGridColumn); bool typeInitialized; var valuePropertyType = getValuePropertyType( valuePropertyBindingPath, GetItemSourceElementType(out typeInitialized)); var filterType = FilterTypeHelper.GetFilterType( valuePropertyType, AssignedDataGridColumn is DataGridComboBoxColumn, DataGridColumnExtensions.GetIsBetweenFilterControl(AssignedDataGridColumn)); string queryString = String.Empty; string queryStringTo = String.Empty; FilterCurrentData = new FilterData( FilterOperator.Undefined, filterType, valuePropertyBindingPath, valuePropertyType, queryString, queryStringTo, typeInitialized, DataGridColumnExtensions.GetIsCaseSensitiveSearch(AssignedDataGridColumn)); }
public void WithNullFilterTypes_ShouldThrowException() { var value = Guid.NewGuid().ToString(); var exception = Assert.Throws <ArgumentException>(() => FilterTypeHelper.SelectFilterTypes(null, value)); Assert.Equal(ErrorConstants.CantBeNullParameter, exception.Message); }
public void WithNotExistingValue_ShouldNotSelectAnything() { var filterTypes = new List <FilterTypeBindingModel>(); this.AddFilterModels(filterTypes); var value = Guid.NewGuid().ToString(); FilterTypeHelper.SelectFilterTypes(filterTypes, value); Assert.True(filterTypes.All(ft => ft.IsSelected == false)); }
public void WithExistingValue_ShouldSelectCorrectFilterType() { var filterTypes = new List <FilterTypeBindingModel>(); var value = Guid.NewGuid().ToString(); this.AddFilterModels(filterTypes, value); this.AddFilterModels(filterTypes); FilterTypeHelper.SelectFilterTypes(filterTypes, value); Assert.Single(filterTypes, ft => ft.IsSelected == true && ft.Value == value); }
public async Task <IActionResult> Index() { var allCars = this.carRepository.GetAll(); var searchServiceModel = await this.homeService.GetSearchModelAsync(allCars, CarType.NewCar); var searchBindingModel = Mapper.Map <HomeSearchBindingModel>(searchServiceModel); FilterTypeHelper.SelectFilterTypes(searchBindingModel.CarTypes, CarType.NewCar.ToString()); var model = new HomeViewModel(); model.SearchModel = searchBindingModel; model.TargetUrlsPublicIds.Add( MainPhotoTargetUrl, MainPhotoPublicId); return(View(model)); }
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)); }