Skip to content

Instantly share code, notes, and snippets.

@nick-hoang
Last active October 31, 2018 06:34
Show Gist options
  • Save nick-hoang/32b29b26db45a7e9cdb43df2a5b2c292 to your computer and use it in GitHub Desktop.
Save nick-hoang/32b29b26db45a7e9cdb43df2a5b2c292 to your computer and use it in GitHub Desktop.
Umbraco - move published content without raising events
public class Mover {
public void PerformMovePublishedContent(IContent content, int parentId, int userId = 0)
{
if(content.ParentId == parentId)
{
return;
}
var contentService = ApplicationContext.Current.Services.ContentService;
if (parentId == Constants.System.Root)
{
content.Path = string.Concat(Constants.System.Root, ",", content.Id);
content.Level = 1;
}
else
{
var parent = contentService.GetById(parentId);
content.Path = string.Concat(parent.Path, ",", content.Id);
content.Level = parent.Level + 1;
}
content.ParentId = parentId;
contentService.SaveAndPublishWithStatus(content, userId, false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment