Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Victor 25 posts 146 karma points
    Dec 01, 2017 @ 17:09
    Victor
    0

    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.

  • Matt Darby 28 posts 391 karma points c-trib
    Dec 02, 2017 @ 14:38
    Matt Darby
    100

    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:

    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
        }
    }
    
  • Victor 25 posts 146 karma points
    Dec 04, 2017 @ 15:48
    Victor
    0

    Hey Matt, thanks for the reply, I tested it and it worked, it returned the parent ID even though the content was deleted.

Please Sign in or register to post replies

Write your reply to:

Draft