Beispiel #1
0
        internal AdSearchResultModel AdvancedSearchAds(AdvancedAdSearchModel searchQuery)
        {
            // This search relies on a selected category
            Category selectedCategory = _repository.Get <Category>(searchQuery.CategorySelectedId);

            // create search parameters object from AdvancedAdSearchModel
            AdSearchParameters searchParameters = CreateSearchParameters(searchQuery);

            // call repo with Type T based on switch on category with parameters (same for all objects)
            IList <SearchAdCache> searchResult = new List <SearchAdCache>();

            switch (selectedCategory.Type)
            {
            case AdTypeEnum.CarAd:
                searchResult = _searchRepository.AdvancedSearchAds <CarAd>(searchParameters);
                break;

            case AdTypeEnum.OtherVehiculeAd:
                searchResult = _searchRepository.AdvancedSearchAds <OtherVehicleAd>(searchParameters);
                break;

            case AdTypeEnum.MotoAd:
                searchResult = _searchRepository.AdvancedSearchAds <MotoAd>(searchParameters);
                break;

            case AdTypeEnum.RealEstateAd:
                searchResult = _searchRepository.AdvancedSearchAds <RealEstateAd>(searchParameters);
                break;

            case AdTypeEnum.MotorBoatAd:
                searchResult = _searchRepository.AdvancedSearchAds <MotorBoatAd>(searchParameters);
                break;

            case AdTypeEnum.SailingBoatAd:
                searchResult = _searchRepository.AdvancedSearchAds <SailingBoatAd>(searchParameters);
                break;

            case AdTypeEnum.MotorBoatEngineAd:
                searchResult = _searchRepository.AdvancedSearchAds <MotorBoatEngineAd>(searchParameters);
                break;

            case AdTypeEnum.WaterSportAd:
                searchResult = _searchRepository.AdvancedSearchAds <WaterSportAd>(searchParameters);
                break;

            case AdTypeEnum.Ad:
                searchResult = _searchRepository.AdvancedSearchAds <Ad>(searchParameters);
                break;
            }

            // Create models for search results
            AdSearchResultModel model = new AdSearchResultModel(searchQuery);

            model.SearchResultTotalCount = searchResult.Count;
            model.SearchResult           = searchResult.Select(a => new AdSearchResultItemModel(a)).ToList();

            return(model);
        }