What I'm doing is using the existing data from a table called HORSES and creating an Umbraco Content item as required.
After the content item is found or created, I store the Umbraco Content Id in a reference table. Then, when I view a horse later by its HorseId, it'll load the Content and use properties of the IContent item for that horse, like the ImageCropper property below
Here's the code below. I found yesterday, tho, if I went to a content item and clicked SAVE AND PUBLISHED, they all appeared in the UmbracoHelper context.
// Retrieves or creates Horse Content Item and returns the Umbraco ID
private long GenerateItems(IContentService contentService, HorseResultContent horse)
{
var contentexists = contentService.GetChildrenByName(HORSESFOLDER, horse.HorseName);
bool exists = false;
// Note: The content item is found here via the IContentService, but not in the UmbracoHelper later on in the PartialView
foreach (IContent content in contentexists)
{
contentService.SaveAndPublishWithStatus(content, 0, false);
exists = true;
return content.Id;
}
if (!exists)
{
var newcontent = contentService.CreateContent(horse.HorseName, HORSESFOLDER, "horseItem", 0);
contentService.SaveAndPublishWithStatus(newcontent, 0, false);
var newcontentexists = contentService.GetChildrenByName(HORSESFOLDER, horse.HorseName);
long umbid = 0;
foreach (IContent content in contentexists)
{
umbid = content.Id;
}
return umbid;
}
return 0;
}
Horse.cshtml
@inherits Umbraco.Web.Mvc.UmbracoViewPage<HorseModel>
@{
// Returns null
var horsepage = Umbraco.TypedContent(horse.UmbID);
var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(horsepage.GetPropertyValue<string>("horsePhoto"));
}
var newcontent = contentService.CreateContent(horse.HorseName, HORSESFOLDER, "horseItem", 0);
contentService.SaveAndPublishWithStatus(newcontent, 0, false);
I do add more properties, etc, later on.
But this line here publishes the content item, I can see it in the back office, but it isn't available to the UmbracoHelper, like in my original image.
UmbracoHelper and IContentService.SaveAndPublishWithStatus()
Hi Everyone,
I'm into converting my existing and huge MVC 2 site over to Umbraco.
It's unreal and very mature and I'm slowly getting my head around it.
I'm working with VS 2015 and the dev server is running through the standard IISEXPRESS from VS.
I'm publishing content on the fly via the IContentService.SaveAndPublishWithStatus(). It's all sitting in the folder from the backend
What has got me a bit confused, when I do a Umbraco.Content(id), it doesn't find it.
Looking into the Children through a VS Watch, it's only got the original 4 that were there before the latest batch.
I'm calling umbraco.library.RefreshContent() but they aren't appearing
Can anyone help out please?
thanks Clay!
Hi Clay,
Can you post some code on how you are creating the nodes. Is it some kind of import of content you are trying to do ?
Dave
Hi Dave,
Thanks for your reply.
What I'm doing is using the existing data from a table called HORSES and creating an Umbraco Content item as required.
After the content item is found or created, I store the Umbraco Content Id in a reference table. Then, when I view a horse later by its HorseId, it'll load the Content and use properties of the IContent item for that horse, like the ImageCropper property below
Here's the code below. I found yesterday, tho, if I went to a content item and clicked SAVE AND PUBLISHED, they all appeared in the UmbracoHelper context.
Horse.cshtml
Cheers Clay
I am not sure I understand your code.
Are these horse nodes already in Umbraco? I don't quite get for your first foreach loop.
Surely the whole point of CreateContent is to create new nodes of content with properties.
Are you saying the nodes are present but not published?
Here's the snippet that's only important
It creates the node, if it doesn't exist
I do add more properties, etc, later on.
But this line here publishes the content item, I can see it in the back office, but it isn't available to the UmbracoHelper, like in my original image.
is working on a reply...