当前位置: 首页>>代码示例>>C#>>正文


C# IContentService.CreateContent方法代码示例

本文整理汇总了C#中IContentService.CreateContent方法的典型用法代码示例。如果您正苦于以下问题:C# IContentService.CreateContent方法的具体用法?C# IContentService.CreateContent怎么用?C# IContentService.CreateContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContentService的用法示例。


在下文中一共展示了IContentService.CreateContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNewContent

        /// <summary>
        /// Private method to create new content
        /// </summary>
        /// <param name="contentService"></param>
        /// <param name="contentTypeService"></param>
        private static void CreateNewContent(IContentService contentService, IContentTypeService contentTypeService)
        {
            //We find all ContentTypes so we can show a nice list of everything that is available
            var contentTypes = contentTypeService.GetAllContentTypes();
            var contentTypeAliases = string.Join(", ", contentTypes.Select(x => x.Alias));

            Console.WriteLine("Please enter the Alias of the ContentType ({0}):", contentTypeAliases);
            var contentTypeAlias = Console.ReadLine();

            Console.WriteLine("Please enter the Id of the Parent:");
            var strParentId = Console.ReadLine();
            int parentId;
            if (int.TryParse(strParentId, out parentId) == false)
                parentId = -1;//Default to -1 which is the root

            Console.WriteLine("Please enter the name of the Content to create:");
            var name = Console.ReadLine();

            //Create the Content
            var content = contentService.CreateContent(name, parentId, contentTypeAlias);
            foreach (var property in content.Properties)
            {
                Console.WriteLine("Please enter the value for the Property with Alias '{0}':", property.Alias);
                var value = Console.ReadLine();
                var isValid = property.IsValid(value);
                if (isValid)
                {
                    property.Value = value;
                }
                else
                {
                    Console.WriteLine("The entered value was not valid and thus not saved");
                }
            }

            //Save the Content
            contentService.Save(content);

            Console.WriteLine("Content was saved: " + content.HasIdentity);
        }
开发者ID:johnseto,项目名称:umbraco-console-example,代码行数:45,代码来源:Program.cs

示例2: CreateProductContent

		private IContent CreateProductContent(IContentService contentService, IContent testCategory, string title, string sku, string price, int stock, string metaDescription, string description, bool useVariantStock, string introduction = null, string features = null)
		{
			var product = contentService.CreateContent(title, testCategory, Product.NodeAlias);
			product.SetValue("title", title);
			product.SetValue("url", title);
			product.SetValue("sku", sku);
			product.SetValue("price", price);
			_stockService.SetStock(product.Id, stock, false, string.Empty);

			product.SetValue("metaDescription", metaDescription);
			product.SetValue("description", description);

			if (useVariantStock)
			{
				product.SetValue("useVariantStock", true);
			}

			if (introduction != null)
			{
				if (product.HasProperty("introduction"))
				{
					product.SetValue("introduction", introduction);
				}
			}

			if (features != null)
			{
				if (product.HasProperty("features"))
				{
					product.SetValue("features", features);
				}
			}

			return product;
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:35,代码来源:DocumentTypeInstaller.cs

示例3: CreateVariantGroupContent

		private static IContent CreateVariantGroupContent(IContentService contentService, IContent testProduct, string variantGroup, bool requiredVariant)
		{
			var testProductVariantGroup = contentService.CreateContent(variantGroup, testProduct, ProductVariantGroup.NodeAlias);
			testProductVariantGroup.SetValue("title", variantGroup);
			if (requiredVariant)
			{
				testProductVariantGroup.SetValue("required", true);
			}


			return testProductVariantGroup;
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:12,代码来源:DocumentTypeInstaller.cs

示例4: CreateVariantContent

		private IContent CreateVariantContent(IContentService contentService, IContent testProductVariantGroup, string color, string sku, string price, int stock, string variantName, bool enableBackorders = false)
		{
			var testProductVariant = contentService.CreateContent(variantName, testProductVariantGroup, ProductVariant.NodeAlias);
			testProductVariant.SetValue("title", color);
			testProductVariant.SetValue("sku", sku);
			testProductVariant.SetValue("price", price);
			testProductVariant.SetValue("backorderStatus", "disable");
			_stockService.SubstractStock(testProductVariant.Id, stock, false, string.Empty);

			if (enableBackorders)
			{
				testProductVariant.SetValue("backorderStatus", "enable");
			}

			return testProductVariant;
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:16,代码来源:DocumentTypeInstaller.cs

示例5: GetOrCreateContent

		internal static IContent GetOrCreateContent(IContentType contentType, string contentName, IContentTypeService contentTypeService, IContentService contentService, IContent parentContent, List<IContent> contentList)
		{   
			var content = contentService.GetContentOfContentType(contentType.Id).FirstOrDefault(x => !x.Trashed);
			if (content == null)
			{
				if (parentContent == null)
				{
					content = contentService.CreateContent(contentName, -1, contentType.Alias);
				}
				else
				{
					content = contentService.CreateContent(contentName, parentContent, contentType.Alias);
				}
				contentList.Add(content);
			}
			return content;
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:17,代码来源:ContentInstaller.cs


注:本文中的IContentService.CreateContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。