private void GeneratePageBlockAuths( Dictionary<Guid, Guid> pageGuidDictionary, Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null )
{
var authService = new AuthService( 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> pageIntDictionary = pageService.Queryable()
.Where( p => pageGuidDictionary.Keys.Contains( p.Guid ) || pageGuidDictionary.Values.Contains( p.Guid ) )
.ToDictionary( p => p.Guid, p => p.Id );
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 pageAuths = authService.Queryable().Where( a =>
a.EntityType.Guid == pageGuid && pageIntDictionary.Values.Contains( a.EntityId.Value ) )
.ToList();
var blockAuths = authService.Queryable().Where( a =>
a.EntityType.Guid == blockGuid && blockIntDictionary.Values.Contains( a.EntityId.Value ) )
.ToList();
foreach ( var pageAuth in pageAuths )
{
var newPageAuth = pageAuth.Clone( false );
newPageAuth.CreatedByPersonAlias = null;
newPageAuth.CreatedByPersonAliasId = currentPersonAliasId;
newPageAuth.CreatedDateTime = RockDateTime.Now;
newPageAuth.ModifiedByPersonAlias = null;
newPageAuth.ModifiedByPersonAliasId = currentPersonAliasId;
newPageAuth.ModifiedDateTime = RockDateTime.Now;
newPageAuth.Id = 0;
newPageAuth.Guid = Guid.NewGuid();
newPageAuth.EntityId = pageIntDictionary[pageGuidDictionary[pageIntDictionary.Where( d => d.Value == pageAuth.EntityId.Value ).FirstOrDefault().Key]];
authService.Add( newPageAuth );
}
foreach ( var blockAuth in blockAuths )
{
var newBlockAuth = blockAuth.Clone( false );
newBlockAuth.CreatedByPersonAlias = null;
newBlockAuth.CreatedByPersonAliasId = currentPersonAliasId;
newBlockAuth.CreatedDateTime = RockDateTime.Now;
newBlockAuth.ModifiedByPersonAlias = null;
newBlockAuth.ModifiedByPersonAliasId = currentPersonAliasId;
newBlockAuth.ModifiedDateTime = RockDateTime.Now;
newBlockAuth.Id = 0;
newBlockAuth.Guid = Guid.NewGuid();
newBlockAuth.EntityId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == blockAuth.EntityId.Value ).FirstOrDefault().Key]];
authService.Add( newBlockAuth );
}
rockContext.SaveChanges();
}