Beispiel #1
0
        /// <summary>
        /// Gets the primary location code for given zip code.
        /// </summary>
        public static LocationCode GetPrimaryLocationCodeForZip(string zip, string instance)
        {
            string usOrCanadaZipCode;

            if (!GeneralUtility.TryParseZipCode(zip, out usOrCanadaZipCode))
            {
                return(null);
            }

            if (SessionCache != null && SessionCache.Contains(usOrCanadaZipCode))
            {
                return(SessionCache[usOrCanadaZipCode] as LocationCode);
            }

            var results = new LocationCodes
            {
                Instance = instance,
                Query    = "select * from LOCATION_CODE where zip = :zip_code and PRIMARY_LOC =  'Y'"
            };

            results.AddParameter("zip_code", usOrCanadaZipCode);

            if (results.Execute() && results.Count > 0)
            {
                foreach (LocationCode code in results)
                {
                    if (SessionCache != null)
                    {
                        lock (SessionCache)
                        {
                            if (!SessionCache.Contains(zip))
                            {
                                SessionCache.Add(zip, code);
                            }
                        }
                    }
                    return(code);
                }
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the state of the zip from city.
        /// </summary>
        public static string GetZipFromCityState(string city, string state, string instance)
        {
            var results = new LocationCodes
            {
                Instance = instance,
                Query    =
                    string.Format(
                        "select * from LOCATION_CODE where CITY like '{0}%' and STATE = :state", city)
            };

            results.AddParameter("state", state);

            if (results.Execute() && results.Count > 0)
            {
                foreach (LocationCode code in results)
                {
                    return(code.Zip);
                }
            }

            return("");
        }