Exemple #1
0
        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 ListPart.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 <ContainedPart>() != null)
            {
                return(BuildViewModel(model.As <ContainedPart>().ListContentItemId, model.ContentType));
            }

            var viewModel = new EditContainedPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, nameof(ListPart)) && viewModel.ContainerId != 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.EnableOrdering));
            }

            return(null);
        }
Exemple #2
0
        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);
            }

            return(await base.UpdateAsync(model, updater));
        }
Exemple #3
0
        public override async Task <IDisplayResult> UpdateAsync(DependencyTreePart model, IUpdateModel updater, UpdatePartEditorContext context)
        {
            //copied from ContainedPartDisplayDriver.cs
            var viewModel = new EditContainedPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, "ListPart") && viewModel.ContainerId != null)
            {
                //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.RootContentItemId = viewModel.ContainerId;
                        model.IsRoot            = false;
                    }
                    else
                    {     //otherwise use the same RootContentItemId
                        model.RootContentItemId = index.RootContentItemId;
                        model.IsRoot            = false;
                    }
                }
            }
            else
            {
                //this means this is root content item

                model.RootContentItemId = null;
                model.IsRoot            = true;
            }


            // await updater.TryUpdateModelAsync(model, Prefix, t => t.IsRoot,  t=> t.RootContentItemId);

            return(Edit(model, context));
        }
Exemple #4
0
        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));
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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 ListPart.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 <ContainedPart>() != null)
            {
                return(BuildShape(model.As <ContainedPart>().ListContentItemId));
            }

            var viewModel = new EditContainedPartViewModel();

            if (await updater.TryUpdateModelAsync(viewModel, nameof(ListPart)) && viewModel.ContainerId != null)
            {
                // We are editing a content item that needs to be added to a container
                // so we render the container id as part of the form

                return(BuildShape(viewModel.ContainerId));
            }

            return(null);
        }