/// <summary> /// Clones this Page object to a new Page object /// </summary> /// <param name="source">The source.</param> /// <param name="deepCopy">if set to <c>true</c> a deep copy is made. If false, only the basic entity properties are copied.</param> /// <returns></returns> public static Page Clone(this Page source, bool deepCopy) { if (deepCopy) { return(source.Clone() as Page); } else { var target = new Page(); target.CopyPropertiesFrom(source); return(target); } }
/// <summary> /// This method generates a copy of the given page along with any descendant pages, as well as any blocks on /// any of those pages. /// </summary> /// <param name="sourcePage">The source page.</param> /// <param name="pageGuidDictionary">The dictionary containing the original page guids and the corresponding copied page guids.</param> /// <param name="blockGuidDictionary">The dictionary containing the original block guids and the corresponding copied block guids.</param> /// <param name="includeChildPages">if set to <c>true</c> [include child pages].</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> /// <param name="isRootOfTheCopyOperation">Is this source page the root of the copy operation. Recursive calls to this method set this param as false.</param> /// <returns></returns> private Page GeneratePageCopy(Page sourcePage, Dictionary <Guid, Guid> pageGuidDictionary, Dictionary <Guid, Guid> blockGuidDictionary, bool includeChildPages, int?currentPersonAliasId = null, bool isRootOfTheCopyOperation = true) { var targetPage = sourcePage.Clone(false); targetPage.CreatedByPersonAlias = null; targetPage.CreatedByPersonAliasId = currentPersonAliasId; targetPage.CreatedDateTime = RockDateTime.Now; targetPage.ModifiedByPersonAlias = null; targetPage.ModifiedByPersonAliasId = currentPersonAliasId; targetPage.ModifiedDateTime = RockDateTime.Now; targetPage.BodyCssClass = sourcePage.BodyCssClass; targetPage.Id = 0; targetPage.Guid = Guid.NewGuid(); targetPage.IsSystem = false; pageGuidDictionary.Add(sourcePage.Guid, targetPage.Guid); if (isRootOfTheCopyOperation) { targetPage.InternalName = sourcePage.InternalName + " - Copy"; } foreach (var block in sourcePage.Blocks) { var newBlock = block.Clone(false); newBlock.CreatedByPersonAlias = null; newBlock.CreatedByPersonAliasId = currentPersonAliasId; newBlock.CreatedDateTime = RockDateTime.Now; newBlock.ModifiedByPersonAlias = null; newBlock.ModifiedByPersonAliasId = currentPersonAliasId; newBlock.ModifiedDateTime = RockDateTime.Now; newBlock.Id = 0; newBlock.Guid = Guid.NewGuid(); newBlock.PageId = 0; newBlock.IsSystem = false; blockGuidDictionary.Add(block.Guid, newBlock.Guid); targetPage.Blocks.Add(newBlock); } if (includeChildPages) { foreach (var oldchildPage in sourcePage.Pages) { targetPage.Pages.Add(GeneratePageCopy(oldchildPage, pageGuidDictionary, blockGuidDictionary, includeChildPages, currentPersonAliasId, false)); } } return(targetPage); }