/// <summary>
/// Called after the save operation has been executed
/// </summary>
/// <remarks>
/// This method is only called if <see cref="M:Rock.Data.EntitySaveHook`1.PreSave" /> returns
/// without error.
/// </remarks>
protected override void PostSave()
{
if (this.State == EntityContextState.Deleted)
{
var qualifierValue = Entity.Id.ToString();
var rockContext = ( RockContext )this.RockContext;
var attributeService = new AttributeService(rockContext);
var existingAttributes = attributeService.GetByEntityTypeId(new ConnectionRequest().TypeId, true)
.AsQueryable()
.Where(a =>
a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
a.EntityTypeQualifierValue.Equals(qualifierValue))
.OrderBy(a => a.Order)
.ThenBy(a => a.Name)
.ToList();
foreach (var attr in existingAttributes)
{
attributeService.Delete(attr);
rockContext.SaveChanges();
}
}
base.PostSave();
}