diff --git a/src/Umbraco.Core/Services/DomainService.cs b/src/Umbraco.Core/Services/DomainService.cs index 2fdf3edb93..ca9fe03dcb 100644 --- a/src/Umbraco.Core/Services/DomainService.cs +++ b/src/Umbraco.Core/Services/DomainService.cs @@ -26,10 +26,15 @@ namespace Umbraco.Core.Services } } - public void Delete(IDomain domain) + public Attempt Delete(IDomain domain) { - if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs(domain), this)) - return; + var evtMsgs = EventMessagesFactory.Get(); + if (Deleting.IsRaisedEventCancelled( + new DeleteEventArgs(domain, evtMsgs), + this)) + { + return Attempt.Fail(OperationStatus.Cancelled(evtMsgs)); + } var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateDomainRepository(uow)) @@ -38,8 +43,9 @@ namespace Umbraco.Core.Services uow.Commit(); } - var args = new DeleteEventArgs(domain, false); + var args = new DeleteEventArgs(domain, false, evtMsgs); Deleted.RaiseEvent(args, this); + return Attempt.Succeed(OperationStatus.Success(evtMsgs)); } public IDomain GetByName(string name) @@ -78,12 +84,14 @@ namespace Umbraco.Core.Services } } - public void Save(IDomain domainEntity, bool raiseEvents = true) + public Attempt Save(IDomain domainEntity) { - if (raiseEvents) + var evtMsgs = EventMessagesFactory.Get(); + if (Saving.IsRaisedEventCancelled( + new SaveEventArgs(domainEntity, evtMsgs), + this)) { - if (Saving.IsRaisedEventCancelled(new SaveEventArgs(domainEntity), this)) - return; + return Attempt.Fail(OperationStatus.Cancelled(evtMsgs)); } var uow = UowProvider.GetUnitOfWork(); @@ -93,8 +101,8 @@ namespace Umbraco.Core.Services uow.Commit(); } - if (raiseEvents) - Saved.RaiseEvent(new SaveEventArgs(domainEntity, false), this); + Saved.RaiseEvent(new SaveEventArgs(domainEntity, false, evtMsgs), this); + return Attempt.Succeed(OperationStatus.Success(evtMsgs)); } #region Event Handlers diff --git a/src/Umbraco.Core/Services/IDomainService.cs b/src/Umbraco.Core/Services/IDomainService.cs index 7026eca041..7a6ce21c8a 100644 --- a/src/Umbraco.Core/Services/IDomainService.cs +++ b/src/Umbraco.Core/Services/IDomainService.cs @@ -6,11 +6,11 @@ namespace Umbraco.Core.Services public interface IDomainService : IService { bool Exists(string domainName); - void Delete(IDomain domain); + Attempt Delete(IDomain domain); IDomain GetByName(string name); IDomain GetById(int id); IEnumerable GetAll(bool includeWildcards); IEnumerable GetAssignedDomains(int contentId, bool includeWildcards); - void Save(IDomain domainEntity, bool raiseEvents = true); + Attempt Save(IDomain domainEntity); } } \ No newline at end of file diff --git a/src/Umbraco.Web/WebServices/DomainsApiController.cs b/src/Umbraco.Web/WebServices/DomainsApiController.cs index f3344a7fb7..6446e0152d 100644 --- a/src/Umbraco.Web/WebServices/DomainsApiController.cs +++ b/src/Umbraco.Web/WebServices/DomainsApiController.cs @@ -63,7 +63,15 @@ namespace Umbraco.Web.WebServices LanguageId = model.Language, RootContentId = model.NodeId }; - Services.DomainService.Save(newDomain); + + var saveAttempt = Services.DomainService.Save(newDomain); + if (saveAttempt == false) + { + var response = Request.CreateResponse(HttpStatusCode.BadRequest); + response.Content = new StringContent("Saving new domain failed"); + response.ReasonPhrase = saveAttempt.Result.StatusType.ToString(); + throw new HttpResponseException(response); + } } } @@ -114,7 +122,14 @@ namespace Umbraco.Web.WebServices LanguageId = domainModel.Lang, RootContentId = model.NodeId }; - Services.DomainService.Save(newDomain); + var saveAttempt = Services.DomainService.Save(newDomain); + if (saveAttempt == false) + { + var response = Request.CreateResponse(HttpStatusCode.BadRequest); + response.Content = new StringContent("Saving new domain failed"); + response.ReasonPhrase = saveAttempt.Result.StatusType.ToString(); + throw new HttpResponseException(response); + } } } diff --git a/src/umbraco.cms/businesslogic/web/Domain.cs b/src/umbraco.cms/businesslogic/web/Domain.cs index fe695a25d6..d47766e36e 100644 --- a/src/umbraco.cms/businesslogic/web/Domain.cs +++ b/src/umbraco.cms/businesslogic/web/Domain.cs @@ -107,9 +107,10 @@ namespace umbraco.cms.businesslogic.web if (!e.Cancel) { - ApplicationContext.Current.Services.DomainService.Save(DomainEntity); - - FireAfterSave(e); + if (ApplicationContext.Current.Services.DomainService.Save(DomainEntity)) + { + FireAfterSave(e); + } } } @@ -165,11 +166,13 @@ namespace umbraco.cms.businesslogic.web RootContentId = RootNodeId, LanguageId = LanguageId }; - ApplicationContext.Current.Services.DomainService.Save(domain); - - var e = new NewEventArgs(); - var legacyModel = new Domain(domain); - legacyModel.OnNew(e); + if (ApplicationContext.Current.Services.DomainService.Save(domain)) + { + var e = new NewEventArgs(); + var legacyModel = new Domain(domain); + legacyModel.OnNew(e); + } + } #endregion