Exemplo n.º 1
0
        /// <summary>
        /// The update user profile.
        /// </summary>
        /// <param name="userName">
        /// The user name.
        /// </param>
        private void UpdateUserProfile([NotNull] string userName)
        {
            YafUserProfile userProfile = YafUserProfile.GetProfile(userName);

            userProfile.Country = this.Country.SelectedItem != null
                                      ? this.Country.SelectedItem.Value.Trim()
                                      : string.Empty;

            userProfile.Region = this.Region.SelectedItem != null && this.Country.SelectedItem != null &&
                                 this.Country.SelectedItem.Value.Trim().IsSet()
                                     ? this.Region.SelectedItem.Value.Trim()
                                     : string.Empty;
            userProfile.City       = this.City.Text.Trim();
            userProfile.Location   = this.Location.Text.Trim();
            userProfile.Homepage   = this.HomePage.Text.Trim();
            userProfile.MSN        = this.MSN.Text.Trim();
            userProfile.YIM        = this.YIM.Text.Trim();
            userProfile.AIM        = this.AIM.Text.Trim();
            userProfile.ICQ        = this.ICQ.Text.Trim();
            userProfile.Facebook   = this.Facebook.Text.Trim();
            userProfile.Twitter    = this.Twitter.Text.Trim();
            userProfile.Google     = this.Google.Text.Trim();
            userProfile.XMPP       = this.Xmpp.Text.Trim();
            userProfile.Skype      = this.Skype.Text.Trim();
            userProfile.RealName   = this.Realname.Text.Trim();
            userProfile.Occupation = this.Occupation.Text.Trim();
            userProfile.Interests  = this.Interests.Text.Trim();
            userProfile.Gender     = this.Gender.SelectedIndex;
            userProfile.Blog       = this.Weblog.Text.Trim();

            DateTime userBirthdate;

            if (this.Get <YafBoardSettings>().UseFarsiCalender&& this.CurrentCultureInfo.IsFarsiCulture())
            {
                var persianDate = new PersianDate(this.Birthday.Text);
                userBirthdate = PersianDateConverter.ToGregorianDateTime(persianDate);

                if (userBirthdate > DateTime.MinValue.Date)
                {
                    userProfile.Birthday = userBirthdate.Date;
                }
            }
            else
            {
                DateTime.TryParse(this.Birthday.Text, this.CurrentCultureInfo, DateTimeStyles.None, out userBirthdate);

                if (userBirthdate > DateTime.MinValue.Date)
                {
                    // Attention! This is stored in profile in the user timezone date
                    userProfile.Birthday = userBirthdate.Date;
                }
            }

            userProfile.BlogServiceUrl      = this.WeblogUrl.Text.Trim();
            userProfile.BlogServiceUsername = this.WeblogUsername.Text.Trim();
            userProfile.BlogServicePassword = this.WeblogID.Text.Trim();

            try
            {
                // Sync to User Profile Mirror table while it's dirty
                SettingsPropertyValueCollection settingsPropertyValueCollection = userProfile.PropertyValues;

                LegacyDb.SetPropertyValues(
                    PageContext.PageBoardID,
                    UserMembershipHelper.ApplicationName(),
                    this.currentUserID,
                    settingsPropertyValueCollection);
            }
            catch (Exception ex)
            {
                this.Logger.Log(
                    "Error while syncinng the User Profile",
                    EventLogTypes.Error,
                    this.PageContext.PageUserName,
                    "Edit User Profile page",
                    ex);
            }

            userProfile.Save();
        }