private void ChangeProfileProperty(DSProfileProperty propStore, SEOProfile user, SettingsPropertyValue propValue) { ProfileProperty dbProperty = propStore.FindByPropertyName(user, propValue.Name); if (dbProperty == null) //Create the property if not found { dbProperty = new ProfileProperty(user, propValue.Name); propStore.Insert(dbProperty); } //The property is already deserialized and is null if (propValue.Deserialized && propValue.PropertyValue == null) dbProperty.SetNull(); else //Property is not null { object serializedVal = propValue.SerializedValue; if (serializedVal == null) //null dbProperty.SetNull(); else if (serializedVal is string) //string dbProperty.SetValue((string) serializedVal); else if (serializedVal is byte[]) //binary dbProperty.SetValue((byte[]) serializedVal); else throw new ProfileValueNotSupportedException(propValue.Name); } }
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties) { var username = (string) context[CONTEXT_USERNAME]; ProfileType profileType; if ((bool) context[CONTEXT_ISAUTHENTICATED]) profileType = ProfileType.Authenticated; else profileType = ProfileType.Anonymous; using (var transaction = new TransactionScope(_connName)) { var propStore = DSProfileProperty.Create(_connName); var userStore = DSSEOProfile.Create(_connName); var user = userStore.FindByName(ApplicationName, username); //Create the user if not exist if (user == null) { user = new SEOProfile(ApplicationName, username, profileType); userStore.Insert(user); } bool userChanged = false; foreach (SettingsPropertyValue propValue in properties) { if (propValue.IsDirty) { if (profileType == ProfileType.Anonymous) { var allowAnonymous = (bool) propValue.Property.Attributes[PROP_ATTRIBUTE_ALLOWANONYMOUS]; if (!allowAnonymous) continue; } userChanged = true; ChangeProfileProperty(propStore, user, propValue); } } user.LastActivityDate = DateTime.Now; if (userChanged) user.LastPropertyChangedDate = DateTime.Now; transaction.Commit(); } }