public static SearchCriteria GetZipCriteria(this SqlDataReader reader)
        {
            SearchCriteria searchCriteria  = new SearchCriteria();
            string         valueOrDefault  = reader.GetValueOrDefault <string>("Country");
            string         valueOrDefault2 = reader.GetValueOrDefault <string>("State");
            string         valueOrDefault3 = reader.GetValueOrDefault <string>("Zip");
            string         valueOrDefault4 = reader.GetValueOrDefault <string>("City");

            if (!valueOrDefault.IsNullOrEmpty())
            {
                searchCriteria.CountryCode(valueOrDefault);
            }
            if (!valueOrDefault2.IsNullOrEmpty())
            {
                searchCriteria.StateCode(valueOrDefault2);
            }
            if (!valueOrDefault4.IsNullOrEmpty())
            {
                searchCriteria.City(valueOrDefault4);
            }
            if (!valueOrDefault3.IsNullOrEmpty())
            {
                searchCriteria.Zip(valueOrDefault3);
            }
            return(searchCriteria);
        }
示例#2
0
        private SearchCriteria GetLookupCriteria(string lookupLocation, string countryCode)
        {
            string         str;
            SearchCriteria searchCriterium = new SearchCriteria();
            List <string>  list            = (
                from p in lookupLocation.Split(new char[] { ',' })
                select p.Trim()).ToList <string>();
            int count = list.Count;

            if (countryCode == "USA")
            {
                str = "^[0-9]*-?[0-9]*$";
            }
            else
            {
                str = (countryCode == "CAN" ? "^[a-zA-Z][0-9]([a-zA-Z]( ([0-9]([a-zA-Z][0-9]?)?)?)?)?$" : "^[0-9]+$");
            }
            searchCriterium.CountryCode(countryCode);
            if (!Regex.IsMatch(list[0], str))
            {
                searchCriterium.StateCode(list[count - 1]);
                if (count == 2)
                {
                    searchCriterium.City(list[0]);
                }
                else if (count == 3)
                {
                    searchCriterium.City(list[1]);
                }
            }
            else
            {
                searchCriterium.Zip(list[0]);
                if (count == 2)
                {
                    searchCriterium.StateCode(list[1]);
                }
                else if (count == 3)
                {
                    searchCriterium.City(list[1]);
                    searchCriterium.StateCode(list[2]);
                }
            }
            return(searchCriterium);
        }
示例#3
0
        private static UrlProcessingResult CheckForOldUrl(string url, out string newUrl)
        {
            newUrl = null;
            Match match = OldDetails.Match(url);

            if (match.Success)
            {
                if (TryParseToPropertyType(match.Groups["searchType"].Value, out var type))
                {
                    if (type == SearchType.ProductsAndServices)
                    {
                        ServiceProviderShortVm serviceProviderShortVm = new ServiceProviderShortVm();
                        serviceProviderShortVm.Id                = Convert.ToInt64(match.Groups["listingId"].Value);
                        serviceProviderShortVm.Name              = match.Groups["listingName"].Value;
                        serviceProviderShortVm.Address           = new AddressVm();
                        serviceProviderShortVm.Address.StateCode = match.Groups["stateCode"].Value;
                        serviceProviderShortVm.Address.City      = match.Groups["city"].Value;
                        newUrl = MslcUrlBuilder.DetailsUrl(serviceProviderShortVm);
                    }
                    else
                    {
                        CommunityShortVm communityShortVm = new CommunityShortVm();
                        communityShortVm.Id                = Convert.ToInt64(match.Groups["listingId"].Value);
                        communityShortVm.Name              = match.Groups["listingName"].Value;
                        communityShortVm.Address           = new AddressVm();
                        communityShortVm.Address.StateCode = match.Groups["stateCode"].Value;
                        communityShortVm.Address.City      = match.Groups["city"].Value;
                        newUrl = MslcUrlBuilder.DetailsUrl(communityShortVm, type);
                    }
                    if (!newUrl.IsNullOrEmpty())
                    {
                        return(UrlProcessingResult.RedirectPermanent);
                    }
                    return(UrlProcessingResult.NotFound);
                }
                return(UrlProcessingResult.NotFound);
            }
            Match match2 = OldSearch.Match(url);

            if (match2.Success)
            {
                if (TryParseToPropertyType(match2.Groups["searchType"].Value, out var type2))
                {
                    SearchCriteria criteria = new SearchCriteria();
                    criteria.StateCode(match2.Groups["stateCode"].Value);
                    criteria.City(match2.Groups["city"].Value);
                    newUrl = MslcUrlBuilder.SearchUrl(criteria, type2);
                    if (!newUrl.IsNullOrEmpty())
                    {
                        return(UrlProcessingResult.RedirectPermanent);
                    }
                    return(UrlProcessingResult.NotFound);
                }
                return(UrlProcessingResult.NotFound);
            }
            return(UrlProcessingResult.Continue);
        }
        public static SearchCriteria GetAddressCriteria(this SqlDataReader reader)
        {
            SearchCriteria searchCriteria  = new SearchCriteria();
            string         valueOrDefault  = reader.GetValueOrDefault <string>("Country");
            string         valueOrDefault2 = reader.GetValueOrDefault <string>("State");
            string         valueOrDefault3 = reader.GetValueOrDefault <string>("City");

            if (!valueOrDefault.IsNullOrEmpty())
            {
                searchCriteria.CountryCode(valueOrDefault);
            }
            if (!valueOrDefault2.IsNullOrEmpty())
            {
                searchCriteria.StateCode(valueOrDefault2);
            }
            if (!valueOrDefault3.IsNullOrEmpty())
            {
                searchCriteria.City(valueOrDefault3.SafeToTitleCase());
            }
            return(searchCriteria);
        }
        internal static LookupLocationValidationVm MapToLookupLocationValidationVm(this LookupLocationValidationResult validationResult, SearchType searchType)
        {
            LookupLocationValidationVm lookupLocationValidationVm = new LookupLocationValidationVm();

            if (validationResult.IsValid && validationResult.Criteria.Depth == SearchDepth.Zip)
            {
                SearchCriteria searchCriterium = new SearchCriteria();
                searchCriterium.CountryCode(validationResult.Criteria.CountryCode());
                searchCriterium.StateCode(validationResult.Criteria.StateCode());
                if (!validationResult.Criteria.City().IsNullOrEmpty())
                {
                    searchCriterium.City(validationResult.Criteria.City());
                }
                validationResult.Criteria = searchCriterium;
            }
            lookupLocationValidationVm.IsValid   = validationResult.IsValid;
            lookupLocationValidationVm.Criteria  = (lookupLocationValidationVm.IsValid ? validationResult.Criteria.MapToSearchCriteriaVm(searchType) : new SearchCriteriaVm());
            lookupLocationValidationVm.Variants  = (lookupLocationValidationVm.IsValid ? new List <AutocompleteVm>() : validationResult.Variants.MapToAutocompleteVmList(searchType, string.Empty));
            lookupLocationValidationVm.SearchUrl = (lookupLocationValidationVm.IsValid ? MslcUrlBuilder.SearchUrl(validationResult.Criteria, searchType) : string.Empty);
            return(lookupLocationValidationVm);
        }