本文整理汇总了C#中Rock.Model.AttributeValueService.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# AttributeValueService.Delete方法的具体用法?C# AttributeValueService.Delete怎么用?C# AttributeValueService.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rock.Model.AttributeValueService
的用法示例。
在下文中一共展示了AttributeValueService.Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Job that will run quick SQL queries on a schedule.
///
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute( IJobExecutionContext context )
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
Guid? entryWorkflowType = dataMap.GetString( "EraEntryWorkflow" ).AsGuidOrNull();
Guid? exitWorkflowType = dataMap.GetString( "EraExitWorkflow" ).AsGuidOrNull();
bool updateVisitDates = dataMap.GetBooleanValue( "SetVisitDates" );
var groupTypeList = dataMap.GetString( "GroupTypes" );
// configuration
//
// giving
int exitGivingCount = 1;
// attendance
int exitAttendanceCountShort = 1;
int exitAttendanceCountLong = 8;
// get era dataset from stored proc
var resultContext = new RockContext();
var eraAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_CURRENTLY_AN_ERA.AsGuid() );
var eraStartAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_START_DATE.AsGuid() );
var eraEndAttribute = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_END_DATE.AsGuid() );
resultContext.Database.CommandTimeout = 3600;
var results = resultContext.Database.SqlQuery<EraResult>( "spCrm_FamilyAnalyticsEraDataset" ).ToList();
int personEntityTypeId = EntityTypeCache.Read( "Rock.Model.Person" ).Id;
int attributeEntityTypeId = EntityTypeCache.Read( "Rock.Model.Attribute" ).Id;
int eraAttributeId = AttributeCache.Read( SystemGuid.Attribute.PERSON_ERA_CURRENTLY_AN_ERA.AsGuid() ).Id;
int personAnalyticsCategoryId = CategoryCache.Read( SystemGuid.Category.HISTORY_PERSON_ANALYTICS.AsGuid() ).Id;
foreach (var result in results )
{
// create new rock context for each family (https://weblog.west-wind.com/posts/2014/Dec/21/Gotcha-Entity-Framework-gets-slow-in-long-Iteration-Loops)
RockContext updateContext = new RockContext();
var attributeValueService = new AttributeValueService( updateContext );
var historyService = new HistoryService( updateContext );
// if era ensure it still meets requirements
if ( result.IsEra )
{
if (result.ExitGiftCountDuration < exitGivingCount && result.ExitAttendanceCountDurationShort < exitAttendanceCountShort && result.ExitAttendanceCountDurationLong < exitAttendanceCountLong )
{
// exit era (delete attribute value from each person in family)
var family = new GroupService( updateContext ).Queryable( "Members, Members.Person" ).AsNoTracking().Where( m => m.Id == result.FamilyId ).FirstOrDefault();
if ( family != null ) {
foreach ( var person in family.Members.Select( m => m.Person ) ) {
// remove the era flag
var eraAttributeValue = attributeValueService.Queryable().Where( v => v.AttributeId == eraAttribute.Id && v.EntityId == person.Id ).FirstOrDefault();
if ( eraAttributeValue != null )
{
attributeValueService.Delete( eraAttributeValue );
}
// set end date
var eraEndAttributeValue = attributeValueService.Queryable().Where( v => v.AttributeId == eraEndAttribute.Id && v.EntityId == person.Id ).FirstOrDefault();
if ( eraEndAttributeValue == null )
{
eraEndAttributeValue = new AttributeValue();
eraEndAttributeValue.EntityId = person.Id;
eraEndAttributeValue.AttributeId = eraEndAttribute.Id;
attributeValueService.Add( eraEndAttributeValue );
}
eraEndAttributeValue.Value = RockDateTime.Now.ToString();
// add a history record
if ( personAnalyticsCategoryId != 0 && personEntityTypeId != 0 && attributeEntityTypeId != 0 && eraAttributeId != 0 )
{
History historyRecord = new History();
historyService.Add( historyRecord );
historyRecord.EntityTypeId = personEntityTypeId;
historyRecord.EntityId = person.Id;
historyRecord.CreatedDateTime = RockDateTime.Now;
historyRecord.CreatedByPersonAliasId = person.PrimaryAliasId;
historyRecord.Caption = "eRA";
historyRecord.Summary = "Exited eRA Status";
historyRecord.Verb = "EXITED";
historyRecord.RelatedEntityTypeId = attributeEntityTypeId;
historyRecord.RelatedEntityId = eraAttributeId;
historyRecord.CategoryId = personAnalyticsCategoryId;
}
updateContext.SaveChanges();
}
// launch exit workflow
if ( exitWorkflowType.HasValue )
//.........这里部分代码省略.........
示例2: SaveUserPreference
/// <summary>
/// Saves a <see cref="Rock.Model.Person">Person's</see> user preference setting by key.
/// </summary>
/// <param name="person">The <see cref="Rock.Model.Person"/> who the preference value belongs to.</param>
/// <param name="key">A <see cref="System.String"/> representing the key (name) of the preference setting.</param>
/// <param name="value">The value.</param>
public static void SaveUserPreference( Person person, string key, string value )
{
int? PersonEntityTypeId = Rock.Web.Cache.EntityTypeCache.Read( Person.USER_VALUE_ENTITY ).Id;
using ( var rockContext = new RockContext() )
{
var attributeService = new Model.AttributeService( rockContext );
var attribute = attributeService.Get( PersonEntityTypeId, string.Empty, string.Empty, key );
if ( attribute == null )
{
var fieldTypeService = new Model.FieldTypeService( rockContext );
var fieldType = FieldTypeCache.Read( Rock.SystemGuid.FieldType.TEXT.AsGuid() );
attribute = new Model.Attribute();
attribute.IsSystem = false;
attribute.EntityTypeId = PersonEntityTypeId;
attribute.EntityTypeQualifierColumn = string.Empty;
attribute.EntityTypeQualifierValue = string.Empty;
attribute.Key = key;
attribute.Name = key;
attribute.IconCssClass = string.Empty;
attribute.DefaultValue = string.Empty;
attribute.IsMultiValue = false;
attribute.IsRequired = false;
attribute.Description = string.Empty;
attribute.FieldTypeId = fieldType.Id;
attribute.Order = 0;
attributeService.Add( attribute );
rockContext.SaveChanges();
}
var attributeValueService = new Model.AttributeValueService( rockContext );
var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( attribute.Id, person.Id );
if ( string.IsNullOrWhiteSpace( value ) )
{
// Delete existing value if no existing value
if ( attributeValue != null )
{
attributeValueService.Delete( attributeValue );
}
}
else
{
if ( attributeValue == null )
{
attributeValue = new Model.AttributeValue();
attributeValue.AttributeId = attribute.Id;
attributeValue.EntityId = person.Id;
attributeValueService.Add( attributeValue );
}
attributeValue.Value = value;
}
rockContext.SaveChanges();
}
}
示例3: DeleteGroupAndMemberData
/// <summary>
/// Generic method to delete the members of a group and then the group.
/// </summary>
/// <param name="group">The group.</param>
/// <param name="rockContext">The rock context.</param>
/// <exception cref="System.InvalidOperationException">Unable to delete group: + group.Name</exception>
private void DeleteGroupAndMemberData( Group group, RockContext rockContext )
{
GroupService groupService = new GroupService( rockContext );
// delete addresses
GroupLocationService groupLocationService = new GroupLocationService( rockContext );
if ( group.GroupLocations.Count > 0 )
{
foreach ( var groupLocations in group.GroupLocations.ToList() )
{
group.GroupLocations.Remove( groupLocations );
groupLocationService.Delete( groupLocations );
}
}
// delete members
var groupMemberService = new GroupMemberService( rockContext );
var members = group.Members;
foreach ( var member in members.ToList() )
{
group.Members.Remove( member );
groupMemberService.Delete( member );
}
// delete attribute values
group.LoadAttributes( rockContext );
if ( group.AttributeValues != null )
{
var attributeValueService = new AttributeValueService( rockContext );
foreach ( var entry in group.AttributeValues )
{
var attributeValue = attributeValueService.GetByAttributeIdAndEntityId( entry.Value.AttributeId, group.Id );
if ( attributeValue != null )
{
attributeValueService.Delete( attributeValue );
}
}
}
// now delete the group
if ( groupService.Delete( group ) )
{
// ok
}
else
{
throw new InvalidOperationException( "Unable to delete group: " + group.Name );
}
}
示例4: 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();
}