private void GenerateBlockAttributeValues( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null )
{
var attributeValueService = new AttributeValueService( rockContext );
var pageService = new PageService( rockContext );
var blockService = new BlockService( rockContext );
var pageGuid = Rock.SystemGuid.EntityType.PAGE.AsGuid();
var blockGuid = Rock.SystemGuid.EntityType.BLOCK.AsGuid();
Dictionary<Guid, int> blockIntDictionary = blockService.Queryable()
.Where( p => blockGuidDictionary.Keys.Contains( p.Guid ) || blockGuidDictionary.Values.Contains( p.Guid ) )
.ToDictionary( p => p.Guid, p => p.Id );
var attributeValues = attributeValueService.Queryable().Where( a =>
a.Attribute.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) )
.ToList();
foreach ( var attributeValue in attributeValues )
{
var newAttributeValue = attributeValue.Clone( false );
newAttributeValue.CreatedByPersonAlias = null;
newAttributeValue.CreatedByPersonAliasId = currentPersonAliasId;
newAttributeValue.CreatedDateTime = RockDateTime.Now;
newAttributeValue.ModifiedByPersonAlias = null;
newAttributeValue.ModifiedByPersonAliasId = currentPersonAliasId;
newAttributeValue.ModifiedDateTime = RockDateTime.Now;
newAttributeValue.Id = 0;
newAttributeValue.Guid = Guid.NewGuid();
newAttributeValue.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == attributeValue.EntityId.Value ).FirstOrDefault().Key]];
if ( attributeValue.Attribute.FieldType.Guid == Rock.SystemGuid.FieldType.PAGE_REFERENCE.AsGuid() )
{
if ( pageGuidDictionary.ContainsKey( attributeValue.Value.AsGuid() ) )
{
newAttributeValue.Value = pageGuidDictionary[attributeValue.Value.AsGuid()].ToString();
}
}
attributeValueService.Add( newAttributeValue );
}
rockContext.SaveChanges();
}