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


C# Document.OnNew方法代码示例

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


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

示例1: MakeNew

        public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
        {
            //allows you to cancel a document before anything goes to the DB
            var newingArgs = new DocumentNewingEventArgs()
                                 {
                                     Text = Name,
                                     DocumentType = dct,
                                     User = u,
                                     ParentId = ParentId
                                 };
            Document.OnNewing(newingArgs);
            if (newingArgs.Cancel)
            {
                return null;
            }

            //Create a new IContent object based on the passed in DocumentType's alias, set the name and save it
            IContent content = ApplicationContext.Current.Services.ContentService.CreateContentWithIdentity(Name, ParentId, dct.Alias, u.Id);
            //The content object will only have the 'WasCancelled' flag set to 'True' if the 'Creating' event has been cancelled, so we return null.
            if (((Entity)content).WasCancelled)
                return null;

            //read the whole object from the db
            Document d = new Document(content);

            //event
            NewEventArgs e = new NewEventArgs();
            d.OnNew(e);

            // Log
            LogHelper.Info<Document>(string.Format("New document {0}", d.Id));

            // Run Handler				
            BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);

            // Save doc
            d.Save();

            return d;
        }
开发者ID:saciervo,项目名称:Umbraco-CMS,代码行数:40,代码来源:Document.cs

示例2: MakeNew

        /// <summary>
        /// Creates a new document
        /// </summary>
        /// <param name="Name">The name (.Text property) of the document</param>
        /// <param name="dct">The documenttype</param>
        /// <param name="u">The usercontext under which the action are performed</param>
        /// <param name="ParentId">The id of the parent to the document</param>
        /// <returns>The newly created document</returns>
        public static Document MakeNew(string Name, DocumentType dct, User u, int ParentId)
        {
            //allows you to cancel a document before anything goes to the DB
            var newingArgs = new DocumentNewingEventArgs()
            {
                Text = Name,
                DocumentType = dct,
                User = u,
                ParentId = ParentId
            };
            Document.OnNewing(newingArgs);
            if (newingArgs.Cancel)
            {
                return null;
            }

            Guid newId = Guid.NewGuid();

            // Updated to match level from base node
            CMSNode n = new CMSNode(ParentId);
            int newLevel = n.Level;
            newLevel++;

            //create the cms node first
            CMSNode newNode = MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);

            //we need to create an empty document and set the underlying text property
            Document tmp = new Document(newId, true);
            tmp.SetText(Name);

            //create the content data for the new document
            tmp.CreateContent(dct);

            //now create the document data
            SqlHelper.ExecuteNonQuery("insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
                                      tmp.Id + ", 0, " +
                                      u.Id + ", @versionId, @text)",
                                      SqlHelper.CreateParameter("@versionId", tmp.Version),
                                      SqlHelper.CreateParameter("@text", tmp.Text));

            // Update the sortOrder if the parent was the root!
            if (ParentId == -1)
            {
                newNode.sortOrder = CountLeafNodes(-1, Document._objectType) + 1;
            }

            //read the whole object from the db
            Document d = new Document(newId);

            //event
            NewEventArgs e = new NewEventArgs();
            d.OnNew(e);

            // Log
            Log.Add(LogTypes.New, u, d.Id, "");

            // Run Handler
            umbraco.BusinessLogic.Actions.Action.RunActionHandlers(d, ActionNew.Instance);

            // Save doc
            d.Save();

            return d;
        }
开发者ID:jracabado,项目名称:justEdit-,代码行数:72,代码来源:Document.cs


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