public static void SavePropertyDefault( SiteUser siteUser, mojoProfilePropertyDefinition propertyDefinition) { siteUser.SetProperty( propertyDefinition.Name, propertyDefinition.DefaultValue, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); }
public static void SaveProperty( SiteUser siteUser, Panel parentControl, mojoProfilePropertyDefinition propertyDefinition, Double legacyTimeZoneOffset, TimeZoneInfo timeZone) { String controlID; Control control; if (propertyDefinition.ISettingControlSrc.Length > 0) { controlID = "isc" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { siteUser.SetProperty( propertyDefinition.Name, ((ISettingControl)control).GetValue(), propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } else { switch (propertyDefinition.Type) { case "System.Boolean": controlID = "chk" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { siteUser.SetProperty( propertyDefinition.Name, ((CheckBox)control).Checked, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } break; case "System.DateTime": controlID = "dp" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { DatePickerControl dp = (DatePickerControl)control; if (dp.Text.Length > 0) { DateTime dt; if (DateTime.TryParse( dp.Text, CultureInfo.CurrentCulture, DateTimeStyles.AdjustToUniversal, out dt)) { if (propertyDefinition.IncludeTimeForDate) { if (timeZone != null) { dt = dt.ToUtc(timeZone); } else { dt = dt.AddHours(-legacyTimeZoneOffset); } if (propertyDefinition.Name == "DateOfBirth") { siteUser.DateOfBirth = dt.Date; siteUser.Save(); } else { siteUser.SetProperty( propertyDefinition.Name, dt.ToString(), propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } else { if(propertyDefinition.Name == "DateOfBirth") { siteUser.DateOfBirth = dt.Date; siteUser.Save(); } else { siteUser.SetProperty( propertyDefinition.Name, dt.Date.ToShortDateString(), propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } } else { siteUser.SetProperty( propertyDefinition.Name, dp.Text, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } else // blank { if (propertyDefinition.Name == "DateOfBirth") { siteUser.DateOfBirth = DateTime.MinValue; siteUser.Save(); } else { siteUser.SetProperty( propertyDefinition.Name, String.Empty, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } } break; case "System.String": default: if (propertyDefinition.OptionList.Count > 0) { if (propertyDefinition.Type == "CheckboxList") { controlID = "cbl" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { if (control is CheckBoxList) { CheckBoxList cbl = (CheckBoxList)control; siteUser.SetProperty( propertyDefinition.Name, cbl.Items.SelectedItemsToCommaSeparatedString(), propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } } else { controlID = "dd" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { if (control is DropDownList) { DropDownList dd = (DropDownList)control; if (dd.SelectedIndex > -1) { siteUser.SetProperty( propertyDefinition.Name, dd.SelectedValue, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } } } } else { controlID = "txt" + propertyDefinition.Name; control = parentControl.FindControl(controlID); if (control != null) { siteUser.SetProperty( propertyDefinition.Name, ((TextBox)control).Text, propertyDefinition.SerializeAs, propertyDefinition.LazyLoad); } } break; } } }