My Umbraco site uses external web services to create and publish content. Previously I would delete all child pages of a given root element before creating new ones based upon the response from the webservice however I now wish to adapt this so that the content is updated if a content node of a specific type is found to have a property value that matches a property within the response from the web service. So far I have the following code:
//Umbraco Content Services
int rootID = 1117;
IContentService cs = ApplicationContext.Current.Services.ContentService;
var continentPages = cs.GetChildren(rootID).Where(x => x.ContentType.Alias == "destination");
foreach (var continent in response)
{
foreach (var page in continentPages)
{
if (page.GetValue<int>("continentId") == continent.Id)
{
page.SetValue("continentName", continent.ContinentName + "updated");
page.SetValue("continentNotes", continent.Notes + "updated");
}
else
{
var destination = cs.CreateContent(continent.ContinentName, rootID, "destination");
//Set the properties using the SetValue method, passing in the alias of the property and the value to assign to it
destination.SetValue("continentId", continent.Id);
destination.SetValue("continentName", continent.ContinentName);
destination.SetValue("continentNotes", continent.Notes);
cs.SaveAndPublishWithStatus(destination);
}
var pageNewVal1 = page.GetValue("continentName");
var pageNewVal2 = page.GetValue("continentNotes");
}
}
However, this code doesn't seem to be working so far and merely creates mutiple instances of child nodes that already exist from previous calls. Clearly I am doing something wrong. Is this the way in which content would typically be updated using the Content Service or is there another method that I'm not aware of?
Updating content using Content Service
Hi all,
My Umbraco site uses external web services to create and publish content. Previously I would delete all child pages of a given root element before creating new ones based upon the response from the webservice however I now wish to adapt this so that the content is updated if a content node of a specific type is found to have a property value that matches a property within the response from the web service. So far I have the following code:
However, this code doesn't seem to be working so far and merely creates mutiple instances of child nodes that already exist from previous calls. Clearly I am doing something wrong. Is this the way in which content would typically be updated using the Content Service or is there another method that I'm not aware of?
Any help would be really appreciated.
Jason
is working on a reply...