diff --git a/src/Umbraco.Core/Models/EntityBase/Entity.cs b/src/Umbraco.Core/Models/EntityBase/Entity.cs
index 6c081ea0b4..8df5be5809 100644
--- a/src/Umbraco.Core/Models/EntityBase/Entity.cs
+++ b/src/Umbraco.Core/Models/EntityBase/Entity.cs
@@ -66,6 +66,15 @@ namespace Umbraco.Core.Models.EntityBase
[DataMember]
public DateTime UpdateDate { get; set; }
+ ///
+ /// Gets or sets the WasCancelled flag, which is used to track
+ /// whether some action against an entity was cancelled through some event.
+ /// This only exists so we have a way to check if an event was cancelled through
+ /// the new api, which also needs to take effect in the legacy api.
+ ///
+ [IgnoreDataMember]
+ internal bool WasCancelled { get; set; }
+
///
/// Property changed event
///
diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs
index ee435f0ffa..18f7de78b0 100644
--- a/src/Umbraco.Core/Services/ContentService.cs
+++ b/src/Umbraco.Core/Services/ContentService.cs
@@ -64,13 +64,15 @@ namespace Umbraco.Core.Services
///
public IContent CreateContent(string name, int parentId, string contentTypeAlias, int userId = 0)
{
- IContentType contentType = FindContentTypeByAlias(contentTypeAlias);
- IContent content = null;
+ var contentType = FindContentTypeByAlias(contentTypeAlias);
+ var content = new Content(name, parentId, contentType); ;
if (Creating.IsRaisedEventCancelled(new NewEventArgs(content, contentTypeAlias, parentId), this))
- return content;
+ {
+ content.WasCancelled = true;
+ return content;
+ }
- content = new Content(name, parentId, contentType);
content.CreatorId = userId;
content.WriterId = userId;
@@ -92,13 +94,15 @@ namespace Umbraco.Core.Services
///
public IContent CreateContent(string name, IContent parent, string contentTypeAlias, int userId = 0)
{
- IContentType contentType = FindContentTypeByAlias(contentTypeAlias);
- IContent content = null;
+ var contentType = FindContentTypeByAlias(contentTypeAlias);
+ var content = new Content(name, parent, contentType);
if (Creating.IsRaisedEventCancelled(new NewEventArgs(content, contentTypeAlias, parent), this))
+ {
+ content.WasCancelled = true;
return content;
+ }
- content = new Content(name, parent, contentType);
content.CreatorId = userId;
content.WriterId = userId;
diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs
index 88aab5d5e1..71b7f421b4 100644
--- a/src/Umbraco.Core/Services/MediaService.cs
+++ b/src/Umbraco.Core/Services/MediaService.cs
@@ -46,11 +46,8 @@ namespace Umbraco.Core.Services
///
public IMedia CreateMedia(string name, int parentId, string mediaTypeAlias, int userId = 0)
{
- Models.Media media = null;
- IMediaType mediaType = null;
- if (Creating.IsRaisedEventCancelled(new NewEventArgs(media, mediaTypeAlias, parentId), this))
- return media;
-
+ IMediaType mediaType;
+
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
{
@@ -68,7 +65,13 @@ namespace Umbraco.Core.Services
mediaTypeAlias));
}
- media = new Models.Media(name, parentId, mediaType);
+ var media = new Models.Media(name, parentId, mediaType);
+
+ if (Creating.IsRaisedEventCancelled(new NewEventArgs(media, mediaTypeAlias, parentId), this))
+ {
+ media.WasCancelled = true;
+ return media;
+ }
media.CreatorId = userId;
@@ -90,11 +93,7 @@ namespace Umbraco.Core.Services
///
public IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = 0)
{
- Models.Media media = null;
- IMediaType mediaType = null;
-
- if (Creating.IsRaisedEventCancelled(new NewEventArgs(media, mediaTypeAlias, parent), this))
- return media;
+ IMediaType mediaType;
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateMediaTypeRepository(uow))
@@ -113,7 +112,12 @@ namespace Umbraco.Core.Services
mediaTypeAlias));
}
- media = new Models.Media(name, parent, mediaType);
+ var media = new Models.Media(name, parent, mediaType);
+ if (Creating.IsRaisedEventCancelled(new NewEventArgs(media, mediaTypeAlias, parent), this))
+ {
+ media.WasCancelled = true;
+ return media;
+ }
media.CreatorId = userId;
diff --git a/src/umbraco.cms/businesslogic/media/Media.cs b/src/umbraco.cms/businesslogic/media/Media.cs
index aed7476d5b..f2c0c84847 100644
--- a/src/umbraco.cms/businesslogic/media/Media.cs
+++ b/src/umbraco.cms/businesslogic/media/Media.cs
@@ -1,6 +1,7 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Models;
+using Umbraco.Core.Models.EntityBase;
using umbraco.BusinessLogic;
using umbraco.DataLayer;
using System.Collections;
@@ -85,8 +86,8 @@ namespace umbraco.cms.businesslogic.media
}
var media = ApplicationContext.Current.Services.MediaService.CreateMedia(Name, ParentId, dct.Alias, u.Id);
- //The media object will only be null if the 'Creating' event has been cancelled
- if (media == null)
+ //The media object will only have the 'WasCancelled' flag set to 'True' if the 'Creating' event has been cancelled
+ if (((Entity)media).WasCancelled)
return null;
ApplicationContext.Current.Services.MediaService.Save(media);
diff --git a/src/umbraco.cms/businesslogic/web/Document.cs b/src/umbraco.cms/businesslogic/web/Document.cs
index a470d31fb7..6c9f039976 100644
--- a/src/umbraco.cms/businesslogic/web/Document.cs
+++ b/src/umbraco.cms/businesslogic/web/Document.cs
@@ -7,6 +7,7 @@ using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Logging;
+using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Caching;
using Umbraco.Core.Services;
using umbraco.BusinessLogic;
@@ -288,8 +289,8 @@ namespace umbraco.cms.businesslogic.web
//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.CreateContent(Name, ParentId, dct.Alias, u.Id);
- //The content object will only be null if the 'Creating' event has been cancelled, so we return null.
- if (content == null)
+ //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;
//don't raise events here (false), they will get raised with the d.Save() call.