Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using umbraco.BusinessLogic;
  3. using umbraco.cms.businesslogic.web;
  4. using umbraco.cms.presentation.Trees;
  5. using umbraco.interfaces;
  6.  
  7. namespace Asda.Jobs.EventHandlers
  8. {
  9.   public class CreateDisciplinesOnComplexArticleCreation : ApplicationBase
  10.   {
  11.     public CreateDisciplinesOnComplexArticleCreation()
  12.     {
  13.       // event handler - when a new document is created.
  14.       Document.New += new Document.NewEventHandler(Document_New);
  15.     }
  16.  
  17.     void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
  18.     {
  19.       // we only want to deal with document which are ComplexArticles
  20.       // this is because ComplexArticle, need to have sub page automatically generated.
  21.       if (sender.ContentType.Alias == "publicComplexArticle")
  22.       {
  23.         // let's set the correct document type first
  24.         // and we also need to create the document using the current user.
  25.         DocumentType dt = DocumentType.GetByAlias("publicDisciplineInfoProcess");
  26.         User author = User.GetCurrent();
  27.         // now let's create our document, using the above settings
  28.         Document doc = Document.MakeNew(dt.Text, dt, author, sender.Id);
  29.         // prepare for publishing
  30.         doc.Publish(author);
  31.         // publish document
  32.         umbraco.library.UpdateDocumentCache(doc.Id);
  33.       }
  34.     }
  35.   }
  36. }