Пример #1
0
        /// <summary>
        ///     Sets the values of the specified group of property settings.
        /// </summary>
        /// <param name="context">
        ///     A <see cref="T:System.Configuration.SettingsContext"></see> describing the current application usage.
        /// </param>
        /// <param name="collection">
        ///     A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> representing the group of property
        ///     settings to set.
        /// </param>
        /// <filterpriority>2</filterpriority>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                string          userName   = LoginId(context);
                IUserProfileDao profileDao = MemberShipFactory.CreateProfileDao();


                ProfileValue profileValue = profileDao.FindByLoginId(userName) ??
                                            new ProfileValue
                {
                    LastActivityDate = DateTime.Now,
                    IsAnonymous      = !userIsAuthenticated(context),
                    LoginId          = userName
                };
                foreach (SettingsPropertyValue settingsPropertyValue in collection)
                {
                    if (profileValue.Properities.ContainsKey(settingsPropertyValue.Name))
                    {
                        profileValue.Properities[settingsPropertyValue.Name] = settingsPropertyValue.PropertyValue;
                    }
                    else
                    {
                        profileValue.Properities.Add(settingsPropertyValue.Name, settingsPropertyValue.PropertyValue);
                    }
                }
                profileDao.SaveOrUpdate(profileValue);
                sessionWrapper.Commit();
            }
            finally
            {
                sessionWrapper.Close();
            }
        }