Rock.Model.AttributeService.GetSystemSetting C# (CSharp) Метод

GetSystemSetting() публичный Метод

Returns a global Rock.Model.Attribute by its Key.
public GetSystemSetting ( string key ) : Attribute
key string A representing the name of the Attribute key.
Результат System.Attribute
        public Attribute GetSystemSetting( string key )
        {
            return this.Get( null, Attribute.SYSTEM_SETTING_QUALIFIER, string.Empty, key );
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void SetValue( string key, string value )
        {
            var rockContext = new Rock.Data.RockContext();
            var attributeService = new AttributeService( rockContext );
            var attribute = attributeService.GetSystemSetting( key );

            if ( attribute == null )
            {
                attribute = new Rock.Model.Attribute();
                attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
                attribute.EntityTypeQualifierColumn = Rock.Model.Attribute.SYSTEM_SETTING_QUALIFIER;
                attribute.EntityTypeQualifierValue = string.Empty;
                attribute.Key = key;
                attribute.Name = key.SplitCase();
                attribute.DefaultValue = value;
                attributeService.Add( attribute );
            }
            else
            {
                attribute.DefaultValue = value;
            }

            rockContext.SaveChanges();

            AttributeCache.Flush( attribute.Id );

            var settings = SystemSettings.Read();
            var attributeCache = settings.Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
            if ( attributeCache != null )
            {
                attributeCache.DefaultValue = value;
            }
            else
            {
                settings.Attributes.Add( AttributeCache.Read( attribute.Id ) );
            }
        }