本文整理汇总了C#中Rock.Model.AttributeService.GetGlobalAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeService.GetGlobalAttribute方法的具体用法?C# AttributeService.GetGlobalAttribute怎么用?C# AttributeService.GetGlobalAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeService
的用法示例。
在下文中一共展示了AttributeService.GetGlobalAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
/// <param name="rockContext">The rock context.</param>
public void SetValue( string key, string value, bool saveValue, RockContext rockContext = null )
{
if ( saveValue )
{
if ( rockContext == null )
{
rockContext = new RockContext();
}
// Save new value
var attributeValueService = new AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetGlobalAttribute( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attributeService.Add( attribute );
rockContext.SaveChanges();
Attributes.Add( AttributeCache.Read( attribute.Id ) );
}
attributeValue = new AttributeValue();
attributeValueService.Add( attributeValue );
attributeValue.IsSystem = false;
attributeValue.AttributeId = attribute.Id;
if ( !AttributeValues.Keys.Contains( key ) )
{
AttributeValues.Add( key, new KeyValuePair<string, string>( attribute.Name, value ) );
}
}
attributeValue.Value = value;
rockContext.SaveChanges();
}
var attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null ) // (Should never be null)
{
if ( AttributeValues.Keys.Contains( key ) )
{
AttributeValues[key] = new KeyValuePair<string, string>( attributeCache.Name, value );
}
else
{
AttributeValues.Add( key, new KeyValuePair<string, string>( attributeCache.Name, value ) );
}
}
}
示例2: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
/// <param name="rockContext">The rock context.</param>
public void SetValue( string key, string value, bool saveValue, RockContext rockContext )
{
AttributeCache attributeCache = null;
if ( saveValue )
{
// Save new value
rockContext = rockContext ?? new RockContext();
var attributeValueService = new AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService( rockContext );
var attribute = attributeService.GetGlobalAttribute( key );
if ( attribute == null )
{
attribute = new Rock.Model.Attribute();
attribute.FieldTypeId = FieldTypeCache.Read( new Guid( SystemGuid.FieldType.TEXT ) ).Id;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key.SplitCase();
attributeService.Add( attribute );
rockContext.SaveChanges();
}
attributeValue = new AttributeValue();
attributeValue.IsSystem = false;
attributeValue.AttributeId = attribute.Id;
attributeValueService.Add( attributeValue );
}
attributeValue.Value = value;
rockContext.SaveChanges();
}
lock(_obj)
{
attributeIds = null;
}
AttributeValues.AddOrUpdate( key, value, ( k, v ) => value );
attributeCache = Attributes.FirstOrDefault( a => a.Key.Equals( key, StringComparison.OrdinalIgnoreCase ) );
if ( attributeCache != null )
{
value = attributeCache.FieldType.Field.FormatValue( null, value, attributeCache.QualifierValues, false );
}
AttributeValuesFormatted.AddOrUpdate( key, value, (k, v) => value);
}