Search code examples
razorumbraco7

How to update node properties from a page in Umbraco 7 using razor


I have been hunting around for a solution to this, but cannot find anything for version 7.

I just have to update a date property on an Umbraco 7 node. (not the publish date) Then I need to tell umbraco to republish the page/update caching.

In the code below the individual node is "item", if it finds the item has a checkbox property set to true then it should increment the date by 1 year.

if(item.annual.ToString()=="True")
{
    item.deadlineDate = item.deadlineDate.AddYears(1);
}

Any and all suggestions gratefully welcome,

Regards, Damien Holley


Solution

  • ContentService is your friend :-) https://our.umbraco.org/documentation/Reference/Management/Services/ContentService

    With it, you can both save and publish content.