Creating content node programmatically doesnt show up on website until publish with descendants
I have some code that creates content when a certain doc type is saved for the first time:
private void ContentService_Saved_AddChildrenForStore(IContentService sender, ContentSavedEventArgs e)
{
foreach (var node in e.SavedEntities)
{
var dirty = (IRememberBeingDirty)node;
var isNew = dirty.WasPropertyDirty("Id");
if (!isNew) { continue; }
if (node.ContentType.Alias == Restaurant.ModelTypeAlias
|| node.ContentType.Alias == ShoppingStore.ModelTypeAlias
|| node.ContentType.Alias == ServicesStore.ModelTypeAlias
|| node.ContentType.Alias == SpecialtyStore.ModelTypeAlias
)
{
SaveEventActions.CreateSalesAndJobOpportunitiesChildren(_contentService, node);
}
}
}
public static void CreateSalesAndJobOpportunitiesChildren(IContentService contentService, IContent parent)
{
var sales = contentService.Create("Sales", parent.Key, Sales.ModelTypeAlias);
var jobs = contentService.Create("Job Opportunities", parent.Key, JobOpportunities.ModelTypeAlias);
contentService.SaveAndPublish(sales);
contentService.SaveAndPublish(jobs);
}
And this is the code that retrieves the information I'm trying to display:
public override ActionResult Index(ContentModel model)
{
var salesPage = model.Content as SalesPromotionsPage;
salesPage.Sales = model.Content.Parent.DescendantsOfType(Sale.ModelTypeAlias).Select(x => x as Sale);
return View(salesPage);
}
I can't get any content created from my first codeblock to show up until I select an ancestor and click Publish with descendants. Maybe this is a problem with the front end cache not updating but I'm not sure how to fix it.
The content appears to save in the content tree correctly. I can add child items and everything.
It looks like the problem comes from calling SaveAndPublish() on the child nodes, since this is in the saved event, publish has not been called yet on the parent.
Creating content node programmatically doesnt show up on website until publish with descendants
I have some code that creates content when a certain doc type is saved for the first time:
And this is the code that retrieves the information I'm trying to display:
I can't get any content created from my first codeblock to show up until I select an ancestor and click Publish with descendants. Maybe this is a problem with the front end cache not updating but I'm not sure how to fix it.
The content appears to save in the content tree correctly. I can add child items and everything.
Any help here?
It looks like the problem comes from calling SaveAndPublish() on the child nodes, since this is in the saved event, publish has not been called yet on the parent.
is working on a reply...