Exemplo n.º 1
0
        /// <summary>
        /// Save setting to DB
        /// </summary>
        /// <param name="key">the key </param>
        private void ModifySetting(ConfigurationKeysEnum key)
        {
            using (var repo = _dataService.Repository)
            {
                // The key value must be a string for LINQ to work
                string keyValue = key.ToString();

                var setting = repo.Get <ApplicationSetting>().FirstOrDefault();

                // If the setting isn't found, create a new one
                if (setting == null)
                {
                    setting = new ApplicationSetting {
                        Key = keyValue
                    };
                    repo.Add(setting);
                }

                // Update the value of the setting and save it
                setting.Value = _configurationSettings[key].Value != null
                    ? _configurationSettings[key].ConvertToApplicationSetting()
                    : string.Empty;
                repo.Save();

                var handler = PropertyChanged;
                if (handler != null)
                {
                    handler(this, new PropertyChangedEventArgs(setting.Key));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationSetting"/> class.
        /// </summary>
        /// <param name="key">The key.</param>
        public ConfigurationSetting(ConfigurationKeysEnum key)
        {
            Key = key;
            var fieldInfo = typeof(ConfigurationKeysEnum).GetField(key.ToString());
            var attr      = Attribute.GetCustomAttribute(fieldInfo, typeof(DefaultAttribute)) as DefaultAttribute;

            if (attr != null)
            {
                _valueType = attr.Type;
                _value     = ConvertFromDefault(attr.DefaultValue);
            }
            else
            {
                _valueType = typeof(string);
                Value      = string.Empty;
            }
        }