/// <summary> /// Deletes a script by its name /// </summary> /// <param name="path">Name incl. extension of the Script to delete</param> /// <param name="userId"></param> public void DeleteScript(string path, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { var script = _scriptRepository.Get(path); if (script == null) { scope.Complete(); return; } var deleteEventArgs = new DeleteEventArgs <Script>(script); if (scope.Events.DispatchCancelable(DeletingScript, this, deleteEventArgs)) { scope.Complete(); return; } _scriptRepository.Delete(script); deleteEventArgs.CanCancel = false; scope.Events.Dispatch(DeletedScript, this, deleteEventArgs); Audit(AuditType.Delete, userId, -1, "Script"); scope.Complete(); } }
/// <inheritdoc /> public void DeleteScript(string path, int?userId = null) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { IScript?script = _scriptRepository.Get(path); if (script == null) { scope.Complete(); return; } EventMessages eventMessages = EventMessagesFactory.Get(); var deletingNotification = new ScriptDeletingNotification(script, eventMessages); if (scope.Notifications.PublishCancelable(deletingNotification)) { scope.Complete(); return; } userId ??= Constants.Security.SuperUserId; _scriptRepository.Delete(script); scope.Notifications.Publish(new ScriptDeletedNotification(script, eventMessages).WithStateFrom(deletingNotification)); Audit(AuditType.Delete, userId.Value, -1, "Script"); scope.Complete(); } }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange using (IScope scope = ScopeProvider.CreateScope()) { IScriptRepository repository = CreateRepository(); // Act IScript script = repository.Get("test-script.js"); repository.Delete(script); // Assert Assert.IsFalse(repository.Exists("test-script.js")); } }
public void Delete(ScriptDeleteCommand command) { using (var transaction = new TransactionScope()) { var id = command.Id; var script = scriptRepository.Find(id); if (script == null) { return; } scriptRepository.Delete(script); transaction.Complete(); } }