Rock.Model.PageService.CloneHtmlContent C# (CSharp) Méthode

CloneHtmlContent() private méthode

Copies any HtmlContent in the original page tree over to the corresponding blocks on the copied page tree.
private CloneHtmlContent ( Guid>.Dictionary blockGuidDictionary, RockContext rockContext, int currentPersonAliasId = null ) : void
blockGuidDictionary Guid>.Dictionary The dictionary containing the original block guids and the corresponding copied block guids.
rockContext Rock.Data.RockContext The rock context.
currentPersonAliasId int The current person alias identifier.
Résultat void
        private void CloneHtmlContent( Dictionary<Guid, Guid> blockGuidDictionary, RockContext rockContext, int? currentPersonAliasId = null )
        {
            var htmlContentService = new HtmlContentService( rockContext );
            var blockService = new BlockService( rockContext );

            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 htmlContents = htmlContentService.Queryable().Where( a =>
                blockIntDictionary.Values.Contains( a.BlockId ) )
                .ToList();

            foreach ( var htmlContent in htmlContents )
            {
                var newHtmlContent = htmlContent.Clone( false );
                newHtmlContent.CreatedByPersonAlias = null;
                newHtmlContent.CreatedByPersonAliasId = currentPersonAliasId;
                newHtmlContent.CreatedDateTime = RockDateTime.Now;
                newHtmlContent.ModifiedByPersonAlias = null;
                newHtmlContent.ModifiedByPersonAliasId = currentPersonAliasId;
                newHtmlContent.ModifiedDateTime = RockDateTime.Now;
                newHtmlContent.Id = 0;
                newHtmlContent.Guid = Guid.NewGuid();
                newHtmlContent.BlockId = blockIntDictionary[blockGuidDictionary[blockIntDictionary.Where( d => d.Value == htmlContent.BlockId ).FirstOrDefault().Key]];

                htmlContentService.Add( newHtmlContent );
            }

            rockContext.SaveChanges();
        }