Creating new Item in a Task (umbraco 5 + FluentAPI)
Hey I am trying to create a new item so I can file news away automatically here is the code I have.
using System;
using System.Collections.Generic;
using Umbraco.Hive;
using Umbraco.Framework.Tasks;
using Umbraco.Framework.Context;
using Umbraco.Framework;
using Umbraco.Cms.Web.Context;
using Umbraco.Cms.Web.Tasks;
using Umbraco.Cms.Web.Model;
using Umbraco.Cms.Web;
namespace Umbraco.Gravypower.Whirrakee.Kernel.Tasks
{
[Task("25876d45-b834-48be-a2f5-5f5f024a458b", TaskTriggers.Hive.Revisions.PostAddOrUpdate, ContinueOnFailure = false)]
publicclass FileNews : AbstractTask
{
private IUmbracoApplicationContext _appContext;
public FileNews(IFrameworkContext context, IUmbracoApplicationContext appContext)
: base(context)
{
_appContext = appContext;
}
publicoverridevoid Execute(TaskExecutionContext Context)
{
var cms = _appContext.Hive.Cms();
//gets the item that has triggered this taskvar currentItemID = ((HiveRevisionPostActionEventArgs)Context.EventArgs.CallerEventArgs).Entity.Item.Id;
var currentItem = cms.Content.GetById(currentItemID);
if(currentItem != null)
{
if (currentItem.ContentType.Alias == "news")
{
//grab the new foldervar newsFolder = cms.Content.GetById(Constants.Content.NewsFolder);
//gets the datevar date = currentItem.Attributes["date"].DynamicValue;
var year = (int)date.Year;
var yearFolder = newsFolder.Children().SingleOrDefault<Content>("NodeTypeAlias == @0", year);
if (yearFolder == null)
{
var yearFolderName = year.ToString();
var hiveManager = (IHiveManager)cms;
var contentBuilder = hiveManager.Cms().NewRevision(yearFolderName, yearFolderName, "newsFolder")
.SetParent(newsFolder.Id)
.Publish()
.Commit();
yearFolder = contentBuilder.Content;
}
}
}
}
}
}
This however does not want to work and I cant work out what i am doing wrong can anyone help?
Creating new Item in a Task (umbraco 5 + FluentAPI)
Hey I am trying to create a new item so I can file news away automatically here is the code I have.
This however does not want to work and I cant work out what i am doing wrong can anyone help?
Thanks
Aaron
FYI: looks like this could be the problem
http://our.umbraco.org/forum/core/umbraco-5-general-discussion/31472-FluentAPI-Publish()Commit()-
is working on a reply...