I there any Demo-code of how to Create / Update ContentItem programmable
as well, what doing
_contentManager.UpdateValidateAndCreateAsync()
Learn from Code, you can check OrchardCore.Modules\OrchardCore.Content\Controllers\AdminController there are variety of methods such as New(), CreateAsync(), GetAsync() and much more
We have mentioned a few times to write some unit tests / integration tests to demonstrate usage of this.
Here is some old code from before UpdateValidateAndCreateAsync() that makes a content item for me.
var result = await _contentManager.NewAsync("AgentTestResult");
result.Weld<ContainedPart>();
result.Alter<ContainedPart>(x => x.ListContentItemId = traderAgentTestResultsContentItemId);
result.DisplayText = "[email protected]";
result.Alter<ContentPart>("AgentTestResult", a =>
{
a.Alter<TextField>("Email", a => a.Text = "[email protected]");
a.Alter<TaxonomyField>("TraderType", a =>
{
a.TaxonomyContentItemId = traderTypeContentItemId;
a.TermContentItemIds = new string[] { traderTypeResult.TradingAgentTypeTermId };
});
});
result.Alter<BagPart>("Answers", a =>
{
a.ContentItems = traderTypeResult.Answers;
});
await _contentManager.CreateAsync(result, VersionOptions.Published);
UpdateValidateAndCreateAsync is an extension method to assist calling some content manager methods in the correct sequence, to ensure all the events are fired. Validate is a reasonably resent method which ensures that some important validation, like alias part unicity, and autoroute unicity is maintained (i.e. the result will fail if you try to create something when the autoroute path already exists.
Seb do we need to add a unit test?
Seb do we need to add a unit test?
I think whatever that will exist in the Demo module or / and in documentation are welcome.
Personally, using the GitHub issues to search whatever was asked, not best user friendly option.
Most helpful comment
We have mentioned a few times to write some unit tests / integration tests to demonstrate usage of this.
Here is some old code from before
UpdateValidateAndCreateAsync()that makes a content item for me.UpdateValidateAndCreateAsyncis an extension method to assist calling some content manager methods in the correct sequence, to ensure all the events are fired.Validateis a reasonably resent method which ensures that some important validation, like alias part unicity, and autoroute unicity is maintained (i.e. the result will fail if you try to create something when the autoroute path already exists.