本文整理汇总了C#中IContentService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# IContentService.Save方法的具体用法?C# IContentService.Save怎么用?C# IContentService.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContentService
的用法示例。
在下文中一共展示了IContentService.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ContentService_Created
private static void ContentService_Created(IContentService sender, global::Umbraco.Core.Events.NewEventArgs<IContent> e)
{
if (e.Entity.Id != 0)
{
if (e.Entity.ContentType.Alias.StartsWith(Store.NodeAlias))
{
var reg = new Regex(@"\s*");
var storeAlias = reg.Replace(e.Entity.Name, "");
Umbraco.Helpers.InstallStore(storeAlias, new Document(e.Entity.Id));
e.Entity.Name = storeAlias;
sender.Save(e.Entity);
}
}
}