public override async Task <IDisplayResult> EditAsync(ContentItem model, IUpdateModel updater) { // This method can get called when a new content item is created, at that point // the query string contains a CrossReferencePart.ContainerId value, or when an // existing content item has ContainedPart value. In both cases the hidden field // needs to be rendered in the edit form to maintain the relationship with the parent. if (model.As <CrossReferencedPart>() != null) { return(BuildViewModel(model.As <CrossReferencedPart>().SourceContentItemId, model.As <CrossReferencedPart>().Relation, model.ContentType)); } var viewModel = new EditCrossReferencedPartViewModel(); if (await updater.TryUpdateModelAsync(viewModel, nameof(CrossReferencePart)) && viewModel.ContainerId != null && viewModel.Relation != null && viewModel.ContentType == model.ContentType) { // We are creating a content item that needs to be added to a container // so we render the container id as part of the form, the content type, // and the enable ordering setting. // The content type must be included to prevent any contained items, // such as widgets, from also having a ContainedPart shape built for them. return(BuildViewModel(viewModel.ContainerId, model.ContentType, viewModel.Relation)); } return(null); }
public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var viewModel = new EditCrossReferencedPartViewModel(); // The content type must match the value provided in the query string // in order for the ContainedPart to be included on the Content Item. if (await updater.TryUpdateModelAsync(viewModel, nameof(CrossReferencePart)) && viewModel.ContainerId != null && viewModel.Relation != null && viewModel.ContentType == model.ContentType) { model.Alter <CrossReferencedPart>(x => { x.SourceContentItemId = viewModel.ContainerId; x.Relation = viewModel.Relation; }); } return(await EditAsync(model, updater)); }