本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}