private static NearbySearchResult GetNearbySearchResult(SearchVm searchVm)
        {
            NearbySearchResult result = null;

            if (searchVm.PageType.ToSearchType() != SearchType.ProductsAndServices)
            {
                CommunitiesSearchVm communitiesSearchVm = searchVm as CommunitiesSearchVm;
                if (communitiesSearchVm != null)
                {
                    CommunityNearbySearchModel searchModel = communitiesSearchVm.ToCommunityNearbySearchModel();
                    searchModel = SearchBc.Instance.SearchNearbyCommunities(searchModel);
                    result      = searchModel.Result;
                }
            }
            else
            {
                ServiceProvidersSearchVm serviceProvidersSearchVm = searchVm as ServiceProvidersSearchVm;
                if (serviceProvidersSearchVm != null)
                {
                    NearbySearchModel searchModel2 = serviceProvidersSearchVm.ToNearbySearchModel();
                    searchModel2 = SearchBc.Instance.SearchNearbyServiceProviders(searchModel2);
                    result       = searchModel2.Result;
                }
            }
            return(result);
        }
        internal static CrosslinksVm MapToCrosslinksVm(this NearbySearchResult searchResult, ISearchCriteria sourceCriteria)
        {
            CrosslinksVm crosslinksVm = new CrosslinksVm();

            foreach (SearchCriteria nearbyCity in searchResult.NearbyCities)
            {
                if (!nearbyCity.MapToSearchCriteriaVm().Validate())
                {
                    continue;
                }
                LinkVm linkVm = new LinkVm()
                {
                    InnerText = ClientViewModelsProvider.GetLookupLocation(nearbyCity),
                    Href      = MslcUrlBuilder.SearchUrl(nearbyCity, sourceCriteria.SearchType())
                };
                crosslinksVm.Cities.Add(linkVm);
            }
            foreach (ListingType availableListingType in searchResult.AvailableListingTypes)
            {
                LinkVm linkVm1 = new LinkVm()
                {
                    InnerText = availableListingType.GetEnumLocalizedValue <ListingType>(),
                    Href      = MslcUrlBuilder.SearchUrl(sourceCriteria, availableListingType.ToSearchType())
                };
                crosslinksVm.Categories.Add(linkVm1);
            }
            if (searchResult.IsServiceProvidersAvailable)
            {
                LinkVm linkVm2 = new LinkVm()
                {
                    InnerText = "Products & Services",
                    Href      = MslcUrlBuilder.SearchUrl(sourceCriteria, SearchType.ProductsAndServices)
                };
                crosslinksVm.Categories.Add(linkVm2);
            }
            return(crosslinksVm);
        }
        private static SearchBarVm FillSearchTypeList(SearchBarVm searchBar, SearchVm searchVm)
        {
            List <SearchType> list       = ConverterHelper.EnumToList <SearchType>();
            SearchType        searchType = searchVm.Criteria.SearchType();

            searchBar.SearchTypeList = new List <SearchBarSelectListItem>();
            NearbySearchResult nearbySearchResult = GetNearbySearchResult(searchVm);

            if (nearbySearchResult != null)
            {
                searchBar.Crosslinks = nearbySearchResult.MapToCrosslinksVm(searchVm.Criteria);
            }
            foreach (SearchType item in list)
            {
                SearchBarSelectListItem searchBarSelectListItem = new SearchBarSelectListItem();
                searchBarSelectListItem.Text = item.GetEnumLocalizedValue();
                int num = (int)item;
                searchBarSelectListItem.Value    = num.ToString(CultureInfo.InvariantCulture);
                searchBarSelectListItem.Selected = item == searchType;
                ListingType type;
                if (nearbySearchResult == null)
                {
                    searchBarSelectListItem.UrlValue = MslcUrlBuilder.SearchUrl(searchVm.Criteria, item);
                }
                else if (item.TryToListingType(out type))
                {
                    searchBarSelectListItem.UrlValue = MslcUrlBuilder.SearchUrl(nearbySearchResult.AvailableListingTypes.Contains(type) ? searchVm.Criteria : searchVm.Criteria.CloneLowerDepth(), item);
                }
                else
                {
                    searchBarSelectListItem.UrlValue = MslcUrlBuilder.SearchUrl(nearbySearchResult.IsServiceProvidersAvailable ? searchVm.Criteria : searchVm.Criteria.CloneLowerDepth(), item);
                }
                searchBar.SearchTypeList.Add(searchBarSelectListItem);
            }
            return(searchBar);
        }