本文整理汇总了C#中Rock.Model.AttributeValueService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService.Save方法的具体用法?C# AttributeValueService.Save怎么用?C# AttributeValueService.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeValueService
的用法示例。
在下文中一共展示了AttributeValueService.Save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetValue
/// <summary>
/// Sets the value.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <param name="currentPersonId">The current person id.</param>
/// <param name="saveValue">if set to <c>true</c> [save value].</param>
public void SetValue( string key, string value, int? currentPersonId, bool saveValue )
{
if ( saveValue )
{
using (new Rock.Data.UnitOfWorkScope())
{
// Save new value
var attributeValueService = new AttributeValueService();
var attributeValue = attributeValueService.GetGlobalAttributeValue( key );
if ( attributeValue == null )
{
var attributeService = new AttributeService();
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, currentPersonId);
attributeService.Save(attribute, currentPersonId);
Attributes.Add( AttributeCache.Read( attribute.Id ) );
}
attributeValue = new AttributeValue();
attributeValueService.Add( attributeValue, currentPersonId );
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;
attributeValueService.Save( attributeValue, currentPersonId );
}
}
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: modalDetails_SaveClick
/// <summary>
/// Handles the SaveClick event of the modalDetails control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
protected void modalDetails_SaveClick( object sender, EventArgs e )
{
if ( _displayValueEdit )
{
int attributeId = 0;
if ( hfIdValues.Value != string.Empty && !int.TryParse( hfIdValues.Value, out attributeId ) )
{
attributeId = 0;
}
if ( attributeId != 0 && phEditControl.Controls.Count > 0 )
{
var attribute = Rock.Web.Cache.AttributeCache.Read( attributeId );
AttributeValueService attributeValueService = new AttributeValueService();
var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attributeId, _entityId ).FirstOrDefault();
if ( attributeValue == null )
{
attributeValue = new Rock.Model.AttributeValue();
attributeValue.AttributeId = attributeId;
attributeValue.EntityId = _entityId;
attributeValueService.Add( attributeValue, CurrentPersonId );
}
var fieldType = Rock.Web.Cache.FieldTypeCache.Read( attribute.FieldType.Id );
attributeValue.Value = fieldType.Field.GetEditValue( phEditControl.Controls[0], attribute.QualifierValues );
attributeValueService.Save( attributeValue, CurrentPersonId );
Rock.Web.Cache.AttributeCache.Flush( attributeId );
if ( !_entityTypeId.HasValue && _entityQualifierColumn == string.Empty && _entityQualifierValue == string.Empty && !_entityId.HasValue )
{
Rock.Web.Cache.GlobalAttributesCache.Flush();
}
}
hfIdValues.Value = string.Empty;
modalDetails.Hide();
}
BindGrid();
}
示例3: lvAttributeValues_ItemInserting
void lvAttributeValues_ItemInserting( object sender, ListViewInsertEventArgs e )
{
PlaceHolder phInsertValue = lvAttributeValues.InsertItem.FindControl( "phInsertValue" ) as PlaceHolder;
if ( phInsertValue != null && phInsertValue.Controls.Count == 1 )
{
string value = _attribute.FieldType.Field.GetEditValue( phInsertValue.Controls[0], _attribute.QualifierValues );
var attributeValueService = new AttributeValueService();
var attributeValue = new AttributeValue();
attributeValue.AttributeId = _attribute.Id;
attributeValue.EntityId = _model.Id;
attributeValue.Value = value;
int? maxOrder = attributeValueService.Queryable().
Where( a => a.AttributeId == attributeValue.AttributeId &&
a.EntityId == attributeValue.EntityId).
Select( a => ( int? )a.Order ).Max();
attributeValue.Order = maxOrder.HasValue ? maxOrder.Value + 1 : 0;
attributeValueService.Add( attributeValue, _currentPersonId);
attributeValueService.Save( attributeValue, _currentPersonId );
_model.LoadAttributes();
}
lvAttributeValues.EditIndex = -1;
BindData();
}
示例4: lvAttributeValues_ItemUpdating
void lvAttributeValues_ItemUpdating( object sender, ListViewUpdateEventArgs e )
{
PlaceHolder phEditValue = lvAttributeValues.EditItem.FindControl( "phEditValue" ) as PlaceHolder;
if ( phEditValue != null && phEditValue.Controls.Count == 1 )
{
string value = _attribute.FieldType.Field.GetEditValue( phEditValue.Controls[0], _attribute.QualifierValues );
var attributeValueService = new AttributeValueService();
var attributeValue = attributeValueService.Get( ( int )e.Keys["Id"] );
if ( attributeValue == null )
{
attributeValue = new AttributeValue();
attributeValueService.Add( attributeValue, _currentPersonId );
attributeValue.AttributeId = _attribute.Id;
attributeValue.EntityId = _model.Id;
}
attributeValue.Value = value;
attributeValueService.Save( attributeValue, _currentPersonId );
_model.LoadAttributes();
}
lvAttributeValues.EditIndex = -1;
BindData();
}
示例5: lvAttributeValues_ItemDeleting
void lvAttributeValues_ItemDeleting( object sender, ListViewDeleteEventArgs e )
{
var attributeValueService = new AttributeValueService();
var attributeValue = attributeValueService.Get( ( int )e.Keys["Id"] );
if ( attributeValue != null )
{
attributeValueService.Delete( attributeValue, _currentPersonId );
attributeValueService.Save( attributeValue, _currentPersonId );
_model.LoadAttributes();
}
BindData();
}