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
        public static SiteStructs.CityRegion GetCityRegionForPostalCodeCountry(
            string postalCode, SiteEnums.CountryCodeISO countryCode)
        {
            var cr = new SiteStructs.CityRegion();

            cr.CityName = GetCityForCountryPostalCode(postalCode, countryCode);
            cr.Region = GetStateForPostalCode(postalCode, countryCode, true);

            return cr;
        }
Example #5
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 #6
0
        /// <summary>
        ///     Sends email notification for status updates
        /// </summary>
        /// <param name="userTo"></param>
        /// <param name="userFrom"></param>
        /// <param name="rsp"></param>
        /// <param name="statusUpdateID"></param>
        private void SendNotificationEmail(int userTo, int userFrom, SiteEnums.ResponseType rsp, int statusUpdateID)
        {
            var uaTo = new UserAccount(userTo);
            var uaFrom = new UserAccount(userFrom);
            var uad = new UserAccountDetail();

            uad.GetUserAccountDeailForUser(uaTo.UserAccountID);

            string language = Utilities.GetCurrentLanguageCode();
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);
            string typeGiven;

            switch (rsp)
            {
                case SiteEnums.ResponseType.A:
                    typeGiven = Messages.Applauded;
                    break;
                case SiteEnums.ResponseType.B:
                    typeGiven = Messages.BeatenDown;
                    break;
                case SiteEnums.ResponseType.C:
                    typeGiven = Messages.Commented;
                    break;
                default:
                    typeGiven = Messages.Unknown;
                    break;
            }

            string statupMess = string.Format("{0}{1}{2}{3}{4}{5}{6}{7}",
                typeGiven,
                string.Format("{0}{0}", Environment.NewLine),
                GeneralConfigs.SiteDomain,
                VirtualPathUtility.ToAbsolute("~/account/statusupdate/"),
                statusUpdateID,
                Environment.NewLine + Environment.NewLine,
                Messages.From + Environment.NewLine + Environment.NewLine,
                uaFrom.UrlTo
                );

            string title = string.Format("{0} -> {1}", uaFrom.UserName, typeGiven);

            if (uad.EmailMessages)
            {
                if (_mail == null)
                {
                    _mail = new MailService();
                }
                _mail.SendMail(AmazonCloudConfigs.SendFromEmail, uaTo.EMail, title, statupMess);
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
        }
Example #7
0
        /// <summary>
        ///     A helper method that performs the checks and updates associated with password failure tracking.
        /// </summary>
        private void UpdateFailureCount(string username, SiteEnums.MembershipFailureTypes failureType)
        {
            var eu = new UserAccount(username);
            if (eu.UserAccountID == 0) throw new ProviderException(Messages.UnableToUpdateFailureCount);

            int failureCount = 0;

            if (failureType == SiteEnums.MembershipFailureTypes.password)
            {
                failureCount = Convert.ToInt32(eu.FailedPasswordAttemptCount);
            }

            if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
            {
                failureCount = Convert.ToInt32(eu.FailedPasswordAnswerAttemptCount);
            }

            if (failureCount == 0)
            {
                // First password failure or outside of PasswordAttemptWindow.
                // Start a new password failure count from 1 and a new window starting now.
                if (failureType == SiteEnums.MembershipFailureTypes.password)
                {
                    eu.FailedPasswordAttemptCount = 1;
                    //  eu.FailedPasswordAttemptWindowStart = FromDB.GetUTCDate();
                }
                if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
                {
                    eu.FailedPasswordAnswerAttemptCount = 1;
                    //  eu.FailedPasswordAnswerAttemptWindowStart = FromDB.GetUTCDate();
                }

                try
                {
                    eu.Update();
                }
                catch
                {
                    throw new ProviderException(Messages.UnableToUpdateFailureCountAndWindowStart);
                }
            }
            else
            {
                if (failureCount++ >= MaxInvalidPasswordAttempts)
                {
                    // Max password attempts have exceeded the failure threshold. Lock out the user.
                    eu.IsLockedOut = true;
                    //  eu.LastLockoutDate = FromDB.GetUTCDate();

                    try
                    {
                        eu.Update();
                    }
                    catch
                    {
                        throw new ProviderException(Messages.UnableToLockOutUser);
                    }
                }
                else
                {
                    // Max password attempts have not exceeded the failure threshold. Update
                    // the failure counts. Leave the window the same.
                    if (failureType == SiteEnums.MembershipFailureTypes.password)
                    {
                        eu.FailedPasswordAttemptCount = failureCount;
                    }
                    if (failureType == SiteEnums.MembershipFailureTypes.passwordAnswer)
                    {
                        eu.FailedPasswordAnswerAttemptCount = failureCount;
                    }

                    try
                    {
                        eu.Update();
                    }
                    catch
                    {
                        throw new ProviderException(Messages.UnableToUpdateFailureCount);
                    }
                }
            }
        }
Example #8
0
        private void SendNotificationEmail(int userTo, SiteEnums.ResponseType rsp, int statusUpdateID)
        {
            UserAccount uaTo = new UserAccount(userTo);

            UserAccountDetail uad = new UserAccountDetail();

            uad.GetUserAccountDeailForUser(uaTo.UserAccountID);

            string language = Utilities.GetCurrentLanguageCode();
            // change language for message to
            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(uad.DefaultLanguage);

            string typeGiven = string.Empty;

            if (rsp == SiteEnums.ResponseType.A)
            {
                typeGiven = Messages.Applauded;
            }
            else if (rsp == SiteEnums.ResponseType.B)
            {
                typeGiven = Messages.BeatenDown;
            }
            else if (rsp == SiteEnums.ResponseType.C)
            {
                typeGiven = Messages.Commented;
            }
            else
            {
                typeGiven = Messages.Unknown;
            }

            string statupMess = typeGiven + Environment.NewLine + Environment.NewLine +  BootBaronLib.Configs.GeneralConfigs.SiteDomain +
                System.Web.VirtualPathUtility.ToAbsolute("~/account/statusupdate/" + statusUpdateID.ToString() );

            if (uad.EmailMessages)
            {
                Utilities.SendMail(uaTo.EMail, Messages.New + ": " + Messages.Notifications,
                    Messages.New + ": " + Messages.Notifications + Environment.NewLine + Environment.NewLine +
                    statupMess  );
            }

            Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(language);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(language);
        }
Example #9
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);
        }