Converted RollbackEventArgs to use new event system.

This commit is contained in:
Shannon Deminick
2012-12-16 07:46:19 +05:00
parent 30f3704a1b
commit 5749e4cab3
2 changed files with 21 additions and 18 deletions

View File

@@ -1,4 +1,13 @@
namespace Umbraco.Core.Events
{
public class RollbackEventArgs : System.ComponentModel.CancelEventArgs { }
public class RollbackEventArgs<TEntity> : CancellableObjectEventArgs<TEntity>
{
public RollbackEventArgs(TEntity entity, bool canCancel) : base(entity, canCancel)
{
}
public RollbackEventArgs(TEntity entity) : base(entity)
{
}
}
}

View File

@@ -1135,29 +1135,23 @@ namespace Umbraco.Core.Services
/// <returns>The newly created <see cref="IContent"/> object</returns>
public IContent Rollback(int id, Guid versionId, int userId = -1)
{
var e = new RollbackEventArgs();
var uow = _uowProvider.GetUnitOfWork();
using (var repository = _repositoryFactory.CreateContentRepository(uow))
{
var content = repository.GetByVersion(id, versionId);
if (Rollingback != null)
Rollingback(content, e);
if (RollingBack.IsRaisedEventCancelled(new RollbackEventArgs<IContent>(content), this))
return content;
SetUser(content, userId);
SetWriter(content, userId);
if (!e.Cancel)
{
SetUser(content, userId);
SetWriter(content, userId);
repository.AddOrUpdate(content);
uow.Commit();
repository.AddOrUpdate(content);
uow.Commit();
RolledBack.RaiseEvent(new RollbackEventArgs<IContent>(content, false), this);
if (Rolledback != null)
Rolledback(content, e);
Audit.Add(AuditTypes.RollBack, "Content rollback performed by user", content.WriterId, content.Id);
}
Audit.Add(AuditTypes.RollBack, "Content rollback performed by user", content.WriterId, content.Id);
return content;
}
@@ -1313,12 +1307,12 @@ namespace Umbraco.Core.Services
/// <summary>
/// Occurs before Rollback
/// </summary>
public static event EventHandler<RollbackEventArgs> Rollingback;
public static event TypedEventHandler<IContentService, RollbackEventArgs<IContent>> RollingBack;
/// <summary>
/// Occurs after Rollback
/// </summary>
public static event EventHandler<RollbackEventArgs> Rolledback;
public static event TypedEventHandler<IContentService, RollbackEventArgs<IContent>> RolledBack;
/// <summary>
/// Occurs before Send to Publish