Hello, I'm creating an IContent by using Umbraco's API ContentService method ApplicationContext.Services.ContentService.GetById(id), which returns an IContent.
I'm using the methods MoveToRecycleBin and Publish to dynamically manage certain contents, but when a content is trashed, I can't publish it, it stays in the recycle bin.
Is there a way to get the IContent parent (after it is trashed, the parent becomes -20) so maybe I can use the Move method? I couldn't find a method which restores a content the same way when you manually go into the recycle bin and choose the option to restore.
By default, Umbraco creates a relation "Relate Parent Document On Delete" when you delete a node. You can see this in Developer > Relation Types.
Using the RelationService you could fetch this relation and use it to find the parent ID of the deleted item. A crude example:
var relations = ApplicationContext.Services.RelationService.GetByChildId(1123); // ID of your deleted node
if (relations.Any())
{
var deleteRelation = relations.Where(x => x.RelationType.Alias.InvariantEquals("relateParentDocumentOnDelete")).FirstOrDefault();
if (deleteRelation != null)
{
@deleteRelation.ParentId
}
}
IContent parent when it is trashed
Hello, I'm creating an IContent by using Umbraco's API ContentService method ApplicationContext.Services.ContentService.GetById(id), which returns an IContent.
I'm using the methods MoveToRecycleBin and Publish to dynamically manage certain contents, but when a content is trashed, I can't publish it, it stays in the recycle bin.
Is there a way to get the IContent parent (after it is trashed, the parent becomes -20) so maybe I can use the Move method? I couldn't find a method which restores a content the same way when you manually go into the recycle bin and choose the option to restore.
Thanks.
Hey Victor,
I can think of a workaround:
By default, Umbraco creates a relation "Relate Parent Document On Delete" when you delete a node. You can see this in Developer > Relation Types.
Using the
RelationService
you could fetch this relation and use it to find the parent ID of the deleted item. A crude example:Hey Matt, thanks for the reply, I tested it and it worked, it returned the parent ID even though the content was deleted.
is working on a reply...