/// <summary> /// Clones the content of the page. /// </summary> /// <param name="pageContent">Content of the page.</param> /// <param name="newPage">The new page.</param> /// <param name="createdContents">The created contents.</param> /// <param name="createdPageContents">The created page contents.</param> /// <param name="clonedPageContentReferences">The cloned page content references.</param> private void ClonePageContent(PageContent pageContent, PageProperties newPage, List <Root.Models.Content> createdContents, List <PageContent> createdPageContents, Dictionary <PageContent, PageContent> clonedPageContentReferences) { var newPageContent = new PageContent(); newPageContent.Page = newPage; newPageContent.Order = pageContent.Order; newPageContent.Region = pageContent.Region; createdPageContents.Add(newPageContent); if (pageContent.Content is HtmlContentWidget || pageContent.Content is ServerControlWidget) { // Do not need to clone widgets. newPageContent.Content = pageContent.Content; } else { newPageContent.Content = pageContent.Content.Clone(); createdContents.Add(newPageContent.Content); var draft = pageContent.Content.History.FirstOrDefault(c => c.Status == ContentStatus.Draft && !c.IsDeleted); if (pageContent.Content.Status == ContentStatus.Published && draft != null) { if (newPageContent.Content.History == null) { newPageContent.Content.History = new List <Root.Models.Content>(); } var draftClone = draft.Clone(); draftClone.Original = newPageContent.Content; newPageContent.Content.History.Add(draftClone); repository.Save(draftClone); createdContents.Add(draftClone); } } // Clone page content options. foreach (var option in pageContent.Options.Distinct()) { if (newPageContent.Options == null) { newPageContent.Options = new List <PageContentOption>(); } var newOption = new PageContentOption { Key = option.Key, Value = option.Value, Type = option.Type, PageContent = newPageContent, CustomOption = option.CustomOption }; newPageContent.Options.Add(newOption); repository.Save(newOption); } repository.Save(newPageContent); clonedPageContentReferences.Add(pageContent, newPageContent); }
public PageContentOption CreateNewPageContentOption(PageContent pageContent = null) { var entity = new PageContentOption(); PopulateBaseFields(entity); entity.PageContent = pageContent ?? CreateNewPageContent(); entity.Key = ProvideRandomString(MaxLength.Name); entity.Value = ProvideRandomString(100); entity.Type = ProvideRandomEnumValue <OptionType>(); return(entity); }
/// <summary> /// Executes the specified request. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public bool Execute(PageContentOptionsViewModel model) { if (model != null && !model.PageContentId.HasDefaultValue() && model.WidgetOptions != null) { var pageContent = Repository.AsQueryable <PageContent>() .Where(f => f.Id == model.PageContentId && !f.IsDeleted && !f.Content.IsDeleted) .Fetch(f => f.Content) .ThenFetchMany(f => f.ContentOptions) .FetchMany(f => f.Options) .ToList() .FirstOrDefault(); if (pageContent != null) { UnitOfWork.BeginTransaction(); foreach (var widgetOption in model.WidgetOptions) { var pageContentOption = pageContent.Options.FirstOrDefault(f => f.Key.Trim().Equals(widgetOption.OptionKey.Trim(), StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(widgetOption.OptionValue) && widgetOption.OptionValue != widgetOption.OptionDefaultValue) { if (pageContentOption == null) { pageContentOption = new PageContentOption { PageContent = pageContent, Key = widgetOption.OptionKey, Value = widgetOption.OptionValue, Type = widgetOption.Type }; } else { pageContentOption.Value = widgetOption.OptionValue; pageContentOption.Type = widgetOption.Type; } Repository.Save(pageContentOption); } else if (pageContentOption != null) { Repository.Delete(pageContentOption); } } UnitOfWork.Commit(); } } return(true); }
/// <summary> /// Clones the content of the page. /// </summary> /// <param name="pageContent">Content of the page.</param> /// <param name="newPage">The new page.</param> private void ClonePageContent(PageContent pageContent, PageProperties newPage) { var newPageContent = new PageContent(); newPageContent.Page = newPage; newPageContent.Order = pageContent.Order; newPageContent.Region = pageContent.Region; if (pageContent.Content is HtmlContentWidget || pageContent.Content is ServerControlWidget) { // Do not need to clone widgets. newPageContent.Content = pageContent.Content; } else { newPageContent.Content = pageContent.Content.Clone(); var draft = pageContent.Content.History.FirstOrDefault(c => c.Status == ContentStatus.Draft && !c.IsDeleted); if (pageContent.Content.Status == ContentStatus.Published && draft != null) { if (newPageContent.Content.History == null) { newPageContent.Content.History = new List<Root.Models.Content>(); } var draftClone = draft.Clone(); draftClone.Original = newPageContent.Content; newPageContent.Content.History.Add(draftClone); repository.Save(draftClone); } } // Clone page content options. foreach (var option in pageContent.Options.Distinct()) { if (newPageContent.Options == null) { newPageContent.Options = new List<PageContentOption>(); } var newOption = new PageContentOption { Key = option.Key, Value = option.Value, Type = option.Type, PageContent = newPageContent, CustomOption = option.CustomOption }; newPageContent.Options.Add(newOption); repository.Save(newOption); } repository.Save(newPageContent); }