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


C# IContentService.Save方法代码示例

本文整理汇总了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);
        }
开发者ID:johnseto,项目名称:umbraco-console-example,代码行数:45,代码来源:Program.cs

示例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);
				}
			}
		}
开发者ID:Chuhukon,项目名称:uWebshop-Releases,代码行数:16,代码来源:ApplicationEventHandler.cs


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