I would like to prevent content nodes from being trashed if they have any children. I setup an event handler like so:
public class KeepSafeEvents : ApplicationBase
{
public KeepSafeEvents()
{
Document.BeforeMoveToTrash += new Document.MoveToTrashEventHandler(Document_BeforeMoveToTrash);
}
void Document_BeforeMoveToTrash(Document sender, umbraco.cms.businesslogic.MoveToTrashEventArgs e)
{
if (sender.HasChildren)
{
e.Cancel = true;
}
}
}
However, this doesn't seem to work. I assume it is because the delete process moves the child nodes to trash first before dealing with the parent node (which then has no children). Is there another possible solution? Or am I making a simple mistake above?