Example #1
0
        public PropertyType(SiteEnums.PropertyTypeCode propertyTypeCode)
        {
            if (propertyTypeCode == SiteEnums.PropertyTypeCode.UNKNO) return;

            PropertyTypeCode = propertyTypeCode;

            if (HttpContext.Current == null ||
                HttpRuntime.Cache[CacheName] == null)
            {
                // get a configured DbCommand object
                DbCommand comm = DbAct.CreateCommand();
                // set the stored procedure name
                comm.CommandText = "up_GetPropertyTypeByCode";

                comm.AddParameter("propertyTypeCode", propertyTypeCode.ToString());

                // execute the stored procedure
                DataTable dt = DbAct.ExecuteSelectCommand(comm);

                // was something returned?
                if (dt == null || dt.Rows.Count <= 0) return;

                if (HttpContext.Current != null)
                {
                    HttpRuntime.Cache.AddObjToCache(dt.Rows[0], CacheName);
                }
                Get(dt.Rows[0]);
            }
            else
            {
                Get((DataRow) HttpRuntime.Cache[CacheName]);
            }
        }
Example #2
0
        /// <summary>
        ///     Check to see if this postal code exists for the country, if it is in GB however,
        ///     the list is not currently updated to validate against
        /// </summary>
        /// <param name="postalCode"></param>
        /// <param name="countryCode"></param>
        /// <returns></returns>
        /// <see cref=">http://www.geonames.org/" />
        public static bool IsValidPostalCode(string postalCode, SiteEnums.CountryCodeISO countryCode)
        {
            postalCode = postalCode.Trim();

            if (string.IsNullOrEmpty(postalCode) ||
                countryCode == SiteEnums.CountryCodeISO.U0) return false;

            // get a configured DbCommand object
            DbCommand comm = DbAct.CreateCommand();
            // set the stored procedure name
            comm.CommandText = "up_IsValidPostalCode";
            // create a new parameter
            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@postalcode";
            //param.Value = postalCode.Trim();

            if (countryCode == SiteEnums.CountryCodeISO.US)
            {
                param.Value = (postalCode.Length >= 5) ? postalCode.Substring(0, 5) : string.Empty;
                // it has to be this way for US
            }
            else if (countryCode == SiteEnums.CountryCodeISO.CA)
            {
                param.Value = (postalCode.Length >= 3) ? postalCode.Substring(0, 3) : string.Empty;
                // it has to be this way for CA
            }
            else if (countryCode == SiteEnums.CountryCodeISO.NZ)
            {
                param.Value = (postalCode.Length >= 4) ? postalCode.Substring(0, 4) : string.Empty;
                // it has to be this way for NZ
            }
            else if (countryCode.ToString() == "GB" || countryCode == SiteEnums.CountryCodeISO.UK)
            {
                param.Value = (postalCode.Length >= 3) ? postalCode.Substring(0, 3) : string.Empty;
                // it has to be this way for GB and UK
            }
            else if (countryCode == SiteEnums.CountryCodeISO.JP)
            {
                param.Value = postalCode.Replace("-", string.Empty);
            }
            else
            {
                param.Value = postalCode;
            }

            param.DbType = DbType.String;
            comm.Parameters.Add(param);
            //
            param = comm.CreateParameter();
            param.ParameterName = "@countrycode";
            param.Value = countryCode.ToString();
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            return DbAct.ExecuteScalar(comm) == "1";
        }
Example #3
0
        /// <summary>
        ///     Get the state for the postal code, country
        /// </summary>
        /// <param name="postalCode"></param>
        /// <param name="countryCode"></param>
        /// <param name="returnStateCode"></param>
        /// <returns></returns>
        public static string GetStateForPostalCode(
            string postalCode,
            SiteEnums.CountryCodeISO countryCode,
            bool returnStateCode
            )
        {
            // get a configured DbCommand object
            DbCommand comm = DbAct.CreateCommand();
            // set the stored procedure name
            comm.CommandText = "up_GetStateForPostalCode";

            // create a new parameter
            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@";
            param.Value = (postalCode.Length >= 5) ? postalCode.Substring(0, 5) : string.Empty;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);
            //
            param = comm.CreateParameter();
            param.ParameterName = "@countrycode";
            param.Value = countryCode.ToString();
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            // execute the stored procedure
            string rsult = DbAct.ExecuteScalar(comm);

            if (returnStateCode)
            {
                return GetStateCodeForStateName(rsult);
            }
            return rsult;
        }
Example #4
0
        /// <summary>
        ///     For the given country and postal code, get the city
        /// </summary>
        /// <param name="postalCode"></param>
        /// <param name="countryCode"></param>
        /// <returns></returns>
        public static string GetCityForCountryPostalCode(
            string postalCode,
            SiteEnums.CountryCodeISO countryCode)
        {
            // get a configured DbCommand object
            DbCommand comm = DbAct.CreateCommand();
            // set the stored procedure name
            comm.CommandText = "up_GetCityForCountryPostalCode";
            // create a new parameter
            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@postalcode";

            if (countryCode == SiteEnums.CountryCodeISO.US)
            {
                param.Value = (postalCode.Length >= 5) ? postalCode.Substring(0, 5) : string.Empty;
                // it has to be this way for US
            }
            else if (countryCode == SiteEnums.CountryCodeISO.CA)
            {
                param.Value = (postalCode.Length >= 3) ? postalCode.Substring(0, 3) : string.Empty;
                // it has to be this way for CA
            }
            else if (countryCode == SiteEnums.CountryCodeISO.NZ)
            {
                param.Value = (postalCode.Length >= 4) ? postalCode.Substring(0, 4) : string.Empty;
                // it has to be this way for NZ
            }
            else if (countryCode.ToString() == "GB" || countryCode == SiteEnums.CountryCodeISO.UK)
            {
                param.Value = (postalCode.Length >= 3) ? postalCode.Substring(0, 3) : string.Empty;
                // it has to be this way for GB and UK
            }
            else
            {
                param.Value = postalCode;
            }
            param.DbType = DbType.String;
            comm.Parameters.Add(param);
            //
            param = comm.CreateParameter();
            param.ParameterName = "@countrycode";

            if (countryCode == SiteEnums.CountryCodeISO.UK)
            {
                param.Value = "GB"; // it has to be GB for UK
            }
            else
            {
                param.Value = countryCode.ToString();
            }
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            // execute the stored procedure
            return DbAct.ExecuteScalar(comm);
        }
Example #5
0
        /// <summary>
        ///     Given the cookie name, check if it exists, if it does, check if the name
        ///     in the name enumValue collection exists, if so remove it and add the new one
        /// </summary>
        /// <param name="cn"></param>
        /// <param name="nvc"></param>
        public static void CookieMaker(SiteEnums.CookieName cn, NameValueCollection nvc)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cn.ToString()];

            // if the cookie exists, expire it
            if (cookie != null)
            {
                foreach (string s in nvc)
                {
                    if (cookie.Values[s] != null)
                    {
                        cookie.Values.Remove(s);
                        cookie.Values.Add(s, nvc[s]);
                    }
                    else
                    {
                        cookie.Values.Add(s, nvc[s]);
                    }
                }
            }
            else
            {
                // make a new cookie
                cookie = new HttpCookie(cn.ToString());
                cookie.Values.Add(nvc);
            }

            cookie.Expires = DateTime.UtcNow.AddDays(7);

            HttpContext.Current.Response.Cookies.Add(cookie);
        }