private void SaveAttributes( int entityTypeId, string qualifierColumn, string qualifierValue, ViewStateList<Attribute> viewStateAttributes, RockContext rockContext ) { // Get the existing attributes for this entity type and qualifier value var attributeService = new AttributeService( rockContext ); var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue ); // Delete any of those attributes that were removed in the UI var selectedAttributeGuids = viewStateAttributes.Select( a => a.Guid ); foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) ) { attributeService.Delete( attr ); rockContext.SaveChanges(); Rock.Web.Cache.AttributeCache.Flush( attr.Id ); } // Update the Attributes that were assigned in the UI foreach ( var attributeState in viewStateAttributes ) { Helper.SaveAttributeEdits( attributeState, entityTypeId, qualifierColumn, qualifierValue, rockContext ); } }
private void SaveAttributes( int entityTypeId, string qualifierColumn, string qualifierValue, ViewStateList<Attribute> viewStateAttributes, AttributeService attributeService, AttributeQualifierService qualifierService, CategoryService categoryService ) { // Get the existing attributes for this entity type and qualifier value var attributes = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue ); // Delete any of those attributes that were removed in the UI var selectedAttributeGuids = viewStateAttributes.Select( a => a.Guid ); foreach ( var attr in attributes.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) ) { Rock.Web.Cache.AttributeCache.Flush( attr.Id ); attributeService.Delete( attr, CurrentPersonId ); attributeService.Save( attr, CurrentPersonId ); } // Update the Attributes that were assigned in the UI foreach ( var attributeState in viewStateAttributes ) { Helper.SaveAttributeEdits( attributeState, attributeService, qualifierService, categoryService, entityTypeId, qualifierColumn, qualifierValue, CurrentPersonId ); } }