Exemplo n.º 1
0
 protected static void OnNewing(DocumentNewingEventArgs e)
 {
     if (Newing != null)
     {
         Newing(null, e);
     }
 }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        /// <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;
        }