public virtual bool RemoveProfileData(ProfileData pd) { return Data.Remove(pd); }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection) { string username = (string)context["UserName"]; bool isAuthenticated = (bool)context["IsAuthenticated"]; if (string.IsNullOrEmpty(username)) return; if (collection.Count < 1) return; if (!ProfileExists(username)) CreateProfileForUser(username, isAuthenticated); using (var s = NHOpenIDMembershipProvider.GetNHibernateSession()) { using (s.BeginTransaction()) { foreach (SettingsPropertyValue item in collection) { if (!item.IsDirty) continue; var deletecrit = s.CreateCriteria<Profile>(); deletecrit.CreateCriteria("User", "u"); deletecrit.Add(Expression.Eq("u.Username", username)); deletecrit.Add(Expression.Eq("ApplicationName", m_applicationName)); deletecrit.Add(Expression.Eq("IsAnonymous", !isAuthenticated)); deletecrit.Add(Expression.Eq("Name", item.Name)); var profiles = deletecrit.List<Profile>(); foreach (var profile in profiles) { foreach (var pdata in profile.Data) { s.Delete(pdata); } profile.Data.Clear(); } s.Transaction.Commit(); ProfileData pd = new ProfileData(); pd.Name = item.Name; if (item.Property.SerializeAs == SettingsSerializeAs.String) { pd.ValueString = SerializationHelper.SerializeToBase64(item.PropertyValue); pd.ValueBinary = null; } else if (item.Property.SerializeAs == SettingsSerializeAs.Xml) { item.SerializedValue = SerializationHelper.SerializeToXml<object>(item.PropertyValue, s_serializationNamespace); pd.ValueString = (string)item.SerializedValue; pd.ValueBinary = null; } else if (item.Property.SerializeAs == SettingsSerializeAs.Binary) { item.SerializedValue = SerializationHelper.SerializeToBinary(item.PropertyValue); pd.ValueString = null; pd.ValueBinary = (byte[])item.SerializedValue; } s.Save(pd); foreach (var profile in profiles) { profile.AddProfileData(pd); } s.Transaction.Commit(); } } } UpdateActivityDates(username, isAuthenticated, false); }
public virtual void AddProfileData(ProfileData pd) { Data.Add(pd); }