Example #1
0
        private static ProductPart BuildProduct(string sku, decimal price)
        {
            var product = new ContentItem();

            product.GetOrCreate <PricePart>();
            product.Alter <PricePart>(p => p.Price = new Amount(price, Currency.USDollar));
            product.GetOrCreate <ProductPart>();
            product.Alter <ProductPart>(p => p.Sku = sku);
            return(product.As <ProductPart>());
        }
Example #2
0
        public async Task <JsonResult> UpdateTypeContents()
        {
            var temp = this.DeserializeObject <IEnumerable <NewPartVM> >();

            foreach (var item in temp)
            {
                ContentItem DevicesInfoContentItem = await _contentManager.GetAsync(item.NewID);

                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDisplayName = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDescription = item.NewDescription);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Classify       = item.Classify);
                item.Name = "ContentType_" + item.NewDisplayName;
                if (_contentDefinitionManager.GetTypeDefinition(item.Name) == null)
                {
                }
                else
                {
                    if (item.Classify == false)
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart")
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting))
                                                                      );
                    }
                    else
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart", part => part.WithPosition("2"))
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting).WithPosition("3"))
                                                                      .WithPart("TypeNewClassifyPart", part => part.WithPosition("1"))
                                                                      );
                    }
                }
                DevicesInfoContentItem.Alter <NewPart>(x => x.Name    = item.Name);
                DevicesInfoContentItem.Alter <TitlePart>(x => x.Title = item.NewDisplayName);
                _contentDefinitionManager.GetTypeDefinition(item.Name);
                _session.Save(DevicesInfoContentItem);
            }
            return(this.Jsonp(temp));
        }
Example #3
0
 public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
 {
     if (contentItem.As <BodyPart>() != null)
     {
         contentItem.Alter <BodyPart>(x => x.Body = rpcStruct.Optional <string>("description"));
     }
 }
        public async Task <ContentItem> AssignGroupAsync(ContentItem profile, string groupContentItemId)
        {
            if (profile == null)
            {
                return(null);
            }

            using (var scope = await _shellHost.GetScopeAsync(_shellSettings))
            {
                var contentManager = scope.ServiceProvider.GetRequiredService <IContentManager>();

                profile.Alter <ProfileGroupedPart>(x => x.GroupContentItemId = groupContentItemId);

                profile.Apply(nameof(ProfileGroupedPart), profile.As <ProfileGroupedPart>());
                ContentExtensions.Apply(profile, profile);

                await contentManager.UpdateAsync(profile);

                await contentManager.PublishAsync(profile);

                await _session.CommitAsync();

                return(profile);
            }
        }
Example #5
0
        public void ContentShouldStoreFields()
        {
            var contentItem = new ContentItem();

            contentItem.GetOrCreate <MyPart>();
            contentItem.Alter <MyPart>(x => x.Text = "test");
            contentItem.Alter <MyPart>(x =>
            {
                x.GetOrCreate <MyField>("myField");
                x.Alter <MyField>("myField", f => f.Value = 123);
            });

            var json = JsonConvert.SerializeObject(contentItem);

            Assert.Contains(@"""MyPart"":{""Text"":""test"",""myField"":{""Value"":123}}", json);
        }
        public Task AddChildContentItemReference(ContentItem parentContentItem, ContentItem childContentItem)
        {
            childContentItem.Alter <ContainedPart>(x => x.ListContentItemId = parentContentItem.ContentItemId);
            // }

            return(Task.CompletedTask);
        }
Example #7
0
 public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
 {
     if (contentItem.As <TitlePart>() != null)
     {
         contentItem.Alter <TitlePart>(x => x.Title = rpcStruct.Optional <string>("title"));
     }
 }
Example #8
0
        private static ContentItem BuildProduct(decimal price)
        {
            var product = new ContentItem();

            product.GetOrCreate <PricePart>();
            product.Alter <PricePart>(p => p.Price = new Amount(price, Currency.Dollar));
            return(product);
        }
Example #9
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));
        }
Example #11
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));
        }
Example #12
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));
        }
Example #13
0
        public void ContentShouldOnlyContainParts()
        {
            var contentItem = new ContentItem();

            contentItem.GetOrCreate <MyPart>();
            contentItem.Alter <MyPart>(x => x.Text = "test");

            var json = JsonConvert.SerializeObject(contentItem);

            Assert.Contains(@"""MyPart"":{""Text"":""test""}", json);
        }
        public static ContentItem CreateBarItem()
        {
            var contentItem = new ContentItem();

            // This is just a creator
            contentItem.Alter <ContentPart>("Bar", x =>
            {
                x.Alter <TextField>("Email", x => x.Text = "*****@*****.**");
            });
            return(contentItem);
        }
Example #15
0
        public override void EditPost(XRpcStruct rpcStruct, ContentItem contentItem)
        {
            if (contentItem.As <AutoroutePart>() != null)
            {
                var slug = rpcStruct.Optional <string>("wp_slug");

                if (!string.IsNullOrWhiteSpace(slug))
                {
                    contentItem.Alter <AutoroutePart>(x => x.Path = slug);
                }
            }
        }
Example #16
0
        public void ShouldAlterPart()
        {
            var contentItem = new ContentItem();

            contentItem.GetOrCreate <MyPart>();
            contentItem.Alter <MyPart>(x => x.Text = "test");

            var json = JsonConvert.SerializeObject(contentItem);

            var contentItem2 = JsonConvert.DeserializeObject <ContentItem>(json);

            Assert.NotNull(contentItem2.Content.MyPart);
            Assert.Equal("test", (string)contentItem2.Content.MyPart.Text);
        }
Example #17
0
        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));
        }
        public void MergeReflectsChangesToElements()
        {
            // Setup
            var value       = "merged value";
            var contentItem = new ContentItem();

            var newContentItem = new ContentItem();

            newContentItem.Weld <CustomPart>();
            newContentItem.Alter <CustomPart>(x => x.Value = value);

            // Act
            contentItem.Merge(newContentItem);

            // Test
            var mergedPart = contentItem.As <CustomPart>();

            Assert.Equal(value, mergedPart?.Value);
        }