示例#1
0
 /// <summary>
 /// Deletes all documents of a type, will be invoked if a documenttype is deleted.
 /// 
 /// Note: use with care: this method can result in wast amount of data being deleted.
 /// </summary>
 /// <param Name="dt">The type of which documents should be deleted</param>
 public static void DeleteFromType(DocumentType dt)
 {
     foreach (Content c in getContentOfContentType(dt))
     {
         // due to recursive structure document might already been deleted..
         if (IsNode(c.UniqueId))
         {
             Document tmp = new Document(c.UniqueId);
             tmp.delete();
         }
     }
 }
示例#2
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)
        {
            Guid newId = Guid.NewGuid();
            // Updated to match level from base node
            CMSNode n = new CMSNode(ParentId);
            int newLevel = n.Level;
            newLevel++;
            MakeNew(ParentId, _objectType, u.Id, newLevel, Name, newId);
            Document tmp = new Document(newId, true);
            tmp.CreateContent(dct);
            Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(_ConnString, CommandType.Text,
                                      "insert into cmsDocument (newest, nodeId, published, documentUser, versionId, Text) values (1, " +
                                      tmp.Id + ", 0, " +
                                      u.Id + ", '" + tmp.Version + "', N'" + SqlHelper.SafeString(tmp.Text) + "')");

            // Update the sortOrder if the parent was the root!
            if (ParentId == -1)
            {
                CMSNode c = new CMSNode(newId);
                c.sortOrder = GetRootDocuments().Length + 1;
            }

            Document d = new Document(newId);

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

            // Run Handler				
            Action.RunActionHandlers(d, new ActionNew());

            // Index
            try
            {
                Indexer.IndexNode(_objectType, d.Id, d.Text, d.User.Name, d.CreateDateTime, null, true);
            }
            catch (Exception ee)
            {
                Log.Add(LogTypes.Error, d.User, d.Id,
                        string.Format("Error indexing document: {0}", ee));
            }

            return d;
        }