I am trying to programmatically move content area item from one content area to the other content area but with no luck.
I made web api controller that sends the page Id from the DOJO widget.
From that page ID I loaded the page detatils via IContentRepository and made a writable clone. Then I load block by content reference and insert that block as new content area item and that part is ok. Than I try to remove the content area item from the other content area and ii debug that is done but on the site it is still there. I am certan that this has something to do with the page versions (drafts).
Part of the code (one version of the code):
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var pageRef = new PageReference(data.Id);
var page = contentRepository.Get<LayoutPage>(pageRef);
var pageClone = (LayoutPage)page.CreateWritableClone();
if (pageClone.SecondColumnContentArea != null)
{
foreach (var areaItem in page.SecondColumnContentArea.Items)
{
var block = contentRepository.Get<IContent>(areaItem.ContentLink);
pageClone.FirstColumnContentArea.Items.Add(new ContentAreaItem
{
ContentLink = block.ContentLink
});
}
pageClone.SecondColumnContentArea.Items.Clear();
}
contentRepository.Save((IContent)pageClone, SaveAction.Default | SaveAction.ForceCurrentVersion, AccessLevel.Edit);
I tried all combinations with SaveAction flags and always is the same result.
Any ideas? Did somebody tried something similar?