
Untitled
By: a guest on
May 15th, 2012 | syntax:
None | size: 1.29 KB | hits: 17 | expires: Never
using System;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.cms.presentation.Trees;
using umbraco.interfaces;
namespace Asda.Jobs.EventHandlers
{
public class CreateDisciplinesOnComplexArticleCreation : ApplicationBase
{
public CreateDisciplinesOnComplexArticleCreation()
{
// event handler - when a new document is created.
Document.New += new Document.NewEventHandler(Document_New);
}
void Document_New(Document sender, umbraco.cms.businesslogic.NewEventArgs e)
{
// we only want to deal with document which are ComplexArticles
// this is because ComplexArticle, need to have sub page automatically generated.
if (sender.ContentType.Alias == "publicComplexArticle")
{
// let's set the correct document type first
// and we also need to create the document using the current user.
DocumentType dt = DocumentType.GetByAlias("publicDisciplineInfoProcess");
User author = User.GetCurrent();
// now let's create our document, using the above settings
Document doc = Document.MakeNew(dt.Text, dt, author, sender.Id);
// prepare for publishing
doc.Publish(author);
// publish document
umbraco.library.UpdateDocumentCache(doc.Id);
}
}
}
}