public Attempt<OperationResult?> DeleteContainer(int containerId, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); using (var scope = ScopeProvider.CreateCoreScope()) { var container = _dataTypeContainerRepository.Get(containerId); if (container == null) return OperationResult.Attempt.NoOperation(evtMsgs); // 'container' here does not know about its children, so we need // to get it again from the entity repository, as a light entity var entity = _entityRepository.Get(container.Id); if (entity?.HasChildren ?? false) { scope.Complete(); return Attempt.Fail(new OperationResult(OperationResultType.FailedCannot, evtMsgs)); } var deletingEntityContainerNotification = new EntityContainerDeletingNotification(container, evtMsgs); if (scope.Notifications.PublishCancelable(deletingEntityContainerNotification)) { scope.Complete(); return Attempt.Fail(new OperationResult(OperationResultType.FailedCancelledByEvent, evtMsgs)); } _dataTypeContainerRepository.Delete(container); scope.Notifications.Publish(new EntityContainerDeletedNotification(container, evtMsgs).WithStateFrom(deletingEntityContainerNotification)); scope.Complete(); } // TODO: Audit trail ? return OperationResult.Attempt.Succeed(evtMsgs); }
public Attempt <OperationResult> DeleteContainer(int containerId, int userId = Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); using (var scope = ScopeProvider.CreateScope()) { var container = _dataTypeContainerRepository.Get(containerId); if (container == null) { return(OperationResult.Attempt.NoOperation(evtMsgs)); } // 'container' here does not know about its children, so we need // to get it again from the entity repository, as a light entity var entity = _entityRepository.Get(container.Id); if (entity.HasChildren) { scope.Complete(); return(Attempt.Fail(new OperationResult(OperationResultType.FailedCannot, evtMsgs))); } if (scope.Events.DispatchCancelable(DeletingContainer, this, new DeleteEventArgs <EntityContainer>(container, evtMsgs))) { scope.Complete(); return(Attempt.Fail(new OperationResult(OperationResultType.FailedCancelledByEvent, evtMsgs))); } _dataTypeContainerRepository.Delete(container); scope.Events.Dispatch(DeletedContainer, this, new DeleteEventArgs <EntityContainer>(container, evtMsgs)); scope.Complete(); } // TODO: Audit trail ? return(OperationResult.Attempt.Succeed(evtMsgs)); }