private IList <ProfileProperty> GetProperties(string userName) { if (string.IsNullOrEmpty(userName)) { return(null); } IList <ProfileProperty> properties; using (var transaction = new TransactionScope(mConfiguration)) { var userStore = new ProfileUserDataStore(transaction); ProfileUser user = userStore.FindByName(ApplicationName, userName); if (user == null) { return(null); } var propStore = new ProfilePropertyDataStore(transaction); properties = propStore.FindByUser(user); //Update the last activity date user.LastActivityDate = DateTime.Now; transaction.Commit(); } return(properties); }
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(mConfiguration)) { var propStore = new ProfilePropertyDataStore(transaction); var userStore = new ProfileUserDataStore(transaction); ProfileUser user = userStore.FindByName(ApplicationName, username); //Create the user if not exist if (user == null) { user = new ProfileUser(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(); } }
public override int DeleteProfiles(ProfileInfoCollection profiles) { int profilesDeleted = 0; using (var transaction = new TransactionScope(mConfiguration)) { var profileStore = new ProfileUserDataStore(transaction); foreach (ProfileInfo profileInfo in profiles) { ProfileUser user = profileStore.FindByName(ApplicationName, profileInfo.UserName); if (user != null) { profileStore.Delete(user.Id); profilesDeleted++; } } transaction.Commit(); } return(profilesDeleted); }