private async Task <string[]> RefreshSubModelsFacet(
            VehicleToBodyStyleConfigSearchInputModel vehicleToBodyStyleConfigSearchInputModel)
        {
            var applyFilters = new VehicleToBodyStyleConfigSearchFilters()
            {
                BodyStyleConfigId = vehicleToBodyStyleConfigSearchInputModel.BodyStyleConfigId,
                Regions           = vehicleToBodyStyleConfigSearchInputModel.Regions,
                VehicleTypes      = vehicleToBodyStyleConfigSearchInputModel.VehicleTypes,
                VehicleTypeGroups = vehicleToBodyStyleConfigSearchInputModel.VehicleTypeGroups,
                StartYear         = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.StartYear),
                EndYear           = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.EndYear),
                BodyNumDoors      = vehicleToBodyStyleConfigSearchInputModel.BodyNumDoors,
                BodyTypes         = vehicleToBodyStyleConfigSearchInputModel.BodyTypes,
                Makes             = vehicleToBodyStyleConfigSearchInputModel.Makes,
                Models            = vehicleToBodyStyleConfigSearchInputModel.Models,
            };
            var result =
                await _vehicleToBodyStyleConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                         new SearchOptions
            {
                FacetsToInclude = new List <string>
                {
                    "subModelName,count:1000",
                },
                RecordCount = 0
            });

            var vehicleToBodyStyleConfigSearchViewModel = _vehicleToBodyStyleConfigSearchViewModelMapper.Map(result);

            return(vehicleToBodyStyleConfigSearchViewModel.Facets.SubModels);
        }
        public async Task <VehicleToBodyStyleConfigSearchViewModel> Search(
            VehicleToBodyStyleConfigSearchInputModel vehicleToBodyStyleConfigSearchInputModel)
        {
            var applyFilters = new VehicleToBodyStyleConfigSearchFilters()
            {
                BodyStyleConfigId = vehicleToBodyStyleConfigSearchInputModel.BodyStyleConfigId,
                // vehicle
                Makes     = vehicleToBodyStyleConfigSearchInputModel.Makes,
                Models    = vehicleToBodyStyleConfigSearchInputModel.Models,
                SubModels = vehicleToBodyStyleConfigSearchInputModel.SubModels,
                StartYear = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.StartYear),
                EndYear   = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.EndYear),
                Regions   = vehicleToBodyStyleConfigSearchInputModel.Regions,
                // body
                BodyNumDoors = vehicleToBodyStyleConfigSearchInputModel.BodyNumDoors,
                BodyTypes    = vehicleToBodyStyleConfigSearchInputModel.BodyTypes,
                // others
                VehicleTypes      = vehicleToBodyStyleConfigSearchInputModel.VehicleTypes,
                VehicleTypeGroups = vehicleToBodyStyleConfigSearchInputModel.VehicleTypeGroups
            };

            var result =
                await _vehicleToBodyStyleConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                         new SearchOptions
            {
                FacetsToInclude = new List <string>
                {
                    // vehicle
                    "makeName,count:1000",
                    "modelName,count:1000",
                    "subModelName,count:1000",
                    "regionName,count:1000",
                    // body
                    "bodyNumDoors,count:1000",
                    "bodyTypeName,count:1000",
                    // others
                    "vehicleTypeName,count:1000",
                    "vehicleTypeGroupName,count:1000",
                },
                RecordCount      = 1000,
                ReturnTotalCount = true
            });

            var viewModel = _vehicleToBodyStyleConfigSearchViewModelMapper.Map(result);

            return(viewModel);
        }
        private async Task <string[]> RefreshBodyTypesFacet(
            VehicleToBodyStyleConfigSearchInputModel vehicleToBodyStyleConfigSearchInputModel)
        {
            var applyFilters = new VehicleToBodyStyleConfigSearchFilters()
            {
            };
            var result = await _vehicleToBodyStyleConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                                  new SearchOptions
            {
                FacetsToInclude = new List <string>
                {
                    "bodyTypeName,count:1000",
                },
                RecordCount = 0
            });

            var vehicleToBodyStyleConfigSearchViewModel = _vehicleToBodyStyleConfigSearchViewModelMapper.Map(result);

            return(vehicleToBodyStyleConfigSearchViewModel.Facets.BodyTypes);
        }
        public async Task <VehicleToBodyStyleConfigSearchViewModel> RefreshFacets(
            VehicleToBodyStyleConfigSearchInputModel vehicleToBodyStyleConfigSearchInputModel)
        {
            var vehicleToBodyStyleConfigSearchViewModel = new VehicleToBodyStyleConfigSearchViewModel
            {
                Facets = new VehicleToBodyStyleConfigSearchFacets
                {
                    // facets precedence
                    Regions           = await this.RefreshRegionFacet(vehicleToBodyStyleConfigSearchInputModel),
                    VehicleTypeGroups =
                        await this.RefreshVehicleTypeGroupFacet(vehicleToBodyStyleConfigSearchInputModel),
                    VehicleTypes = await RefreshVehicleTypeFacet(vehicleToBodyStyleConfigSearchInputModel),
                    Years        = await RefreshYearFacet(vehicleToBodyStyleConfigSearchInputModel),
                    Makes        = await RefreshMakesFacet(vehicleToBodyStyleConfigSearchInputModel),
                    Models       = await RefreshModelsFacet(vehicleToBodyStyleConfigSearchInputModel),
                    SubModels    = await RefreshSubModelsFacet(vehicleToBodyStyleConfigSearchInputModel),

                    BodyNumDoors = await RefreshBodyNumDoorsFacet(vehicleToBodyStyleConfigSearchInputModel),
                    BodyTypes    = await RefreshBodyTypesFacet(vehicleToBodyStyleConfigSearchInputModel)
                }
            };

            return(vehicleToBodyStyleConfigSearchViewModel);
        }
        public async Task <List <VehicleToBodyStyleConfigViewModel> > GetAssociations(VehicleToBodyStyleConfigSearchInputModel vehicleToBodyStyleConfigSearchInputModel)
        {
            List <VehicleToBodyStyleConfigViewModel> vehicleToBodyStyleConfigs = new List <VehicleToBodyStyleConfigViewModel>();

            var applyFilters = new VehicleToBodyStyleConfigSearchFilters()
            {
                BodyStyleConfigId = vehicleToBodyStyleConfigSearchInputModel.BodyStyleConfigId,
                StartYear         = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.StartYear),
                EndYear           = Convert.ToInt32(vehicleToBodyStyleConfigSearchInputModel.EndYear),
                Makes             = vehicleToBodyStyleConfigSearchInputModel.Makes,
                Models            = vehicleToBodyStyleConfigSearchInputModel.Models,
                SubModels         = vehicleToBodyStyleConfigSearchInputModel.SubModels,
                VehicleTypes      = vehicleToBodyStyleConfigSearchInputModel.VehicleTypes,
                VehicleTypeGroups = vehicleToBodyStyleConfigSearchInputModel.VehicleTypeGroups,
                Regions           = vehicleToBodyStyleConfigSearchInputModel.Regions,
            };

            bool isEndReached = false;
            int  pageNumber   = 1;

            do
            {
                var result = await _vehicleToBodyStyleConfigSearchService.SearchAsync("", applyFilters.ToAzureSearchFilter(),
                                                                                      new SearchOptions()
                {
                    RecordCount = 1000, PageNumber = pageNumber
                });

                if (result != null && result.Documents != null && result.Documents.Any())
                {
                    vehicleToBodyStyleConfigs.AddRange(_vehicleToBodyStyleConfigViewModelMapper.Map(result));

                    pageNumber++;
                }
                else
                {
                    isEndReached = true;
                }
            } while (!isEndReached);

            return(vehicleToBodyStyleConfigs);
        }