public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var viewModel = new EditContainedPartViewModel(); if (await updater.TryUpdateModelAsync(viewModel, nameof(ListPart)) && viewModel.ContainerId != null) { model.Alter <ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId); // If creating get next order number so item is added to the end of the list if (viewModel.EnableOrdering) { var nextOrder = await _containerService.GetNextOrderNumberAsync(viewModel.ContainerId); model.Alter <ContainedPart>(x => x.Order = nextOrder); } } return(await EditAsync(model, updater)); }
public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var viewModel = new EditContainedPartViewModel(); // 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(ListPart)) && viewModel.ContainerId != null && viewModel.ContentType == model.ContentType) { model.Alter <ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId); //add the containers rootid as this items rootid as well (cascade update) //need to find document id d //using documentid get record ContainedPartIndex var contentItemIndex = await _session.QueryIndex <ContentItemIndex>(x => x.ContentItemId == viewModel.ContainerId).FirstOrDefaultAsync(); if (contentItemIndex != null) { var docid = contentItemIndex.DocumentId; var index = await _session.QueryIndex <ContainedPartIndex>(x => x.DocumentId == docid).FirstOrDefaultAsync(); if (index == null) { //this is a node at first level below root so set rootid to contentitemid model.Alter <ContainedPart>(x => x.RootContentItemId = viewModel.ContainerId); } else { //otherwise use the same RootContentItemId model.Alter <ContainedPart>(x => x.RootContentItemId = index.RootContentItemId); } } // If creating get next order number so item is added to the end of the list if (viewModel.EnableOrdering) { var nextOrder = await _containerService.GetNextOrderNumberAsync(viewModel.ContainerId); model.Alter <ContainedPart>(x => x.Order = nextOrder); } } return(await EditAsync(model, updater)); }
public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var viewModel = new EditContainedPartViewModel(); // 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(ListPart)) && viewModel.ContainerId != null && viewModel.ContentType == model.ContentType) { model.Alter <ContainedPart>(x => x.ListContentItemId = viewModel.ContainerId); // If creating get next order number so item is added to the end of the list if (viewModel.EnableOrdering) { var nextOrder = await _containerService.GetNextOrderNumberAsync(viewModel.ContainerId); model.Alter <ContainedPart>(x => x.Order = nextOrder); } } return(await EditAsync(model, updater)); }
public async Task AssignContainerAsync(string containedContentItemId, string containerContentItemId, IUpdateModel updateModel) { //need to also figure the order id to place it //use service Previous in list to get its id or see the OrderController by Dean with drag and drop var containedContentItem = await _contentManager.GetAsync(containedContentItemId, VersionOptions.Published); // var containedPart = containedContentItem?.As<ContainedPart>(); //if (containedPart == null) // { // updateModel.ModelState.AddModelError(nameof(ListPartContentAssignParentContainerFilter), S["The contained content item {0} must already have a contained part.", containedContentItem?.ContentItemId]); // } else { var nextOrder = await _containerService.GetNextOrderNumberAsync(containerContentItemId); containedContentItem.Alter <ContainedPart>(x => { x.ListContentItemId = containerContentItemId; x.Order = nextOrder; }); await _contentManager.UpdateAsync(containedContentItem); // } }