Assign / Add Content Item To ListPart Orchard Core Programmatically

755 Views Asked by At

I have an API to create contentItem, but how can i assign it to other content's ListPart ? for example i have a Audio Album that has a ListPart with content type Audio Item.

currently i'm using content manager

 var contentItem = await _contentManager.NewAsync("AudioItem");

 await _contentManager.CreateAsync(contentItem, VersionOptions.DraftRequired);

 contentItem.DisplayText = name;

 await _contentManager.UpdateAsync(contentItem);

Thank you

1

There are 1 best solutions below

0
Dean Marcussen On BEST ANSWER

You need to use the Weld and Alter extensions to modify a content item.

contentItem.Weld<ContainedPart>();
contentItem.Alter<ContainedPart>(x => x.ListContentItemId  = "id-of-parent");

Weld will add the ContainedPart, and Alter will changes it's value.