/// <summary> /// Saves an <see cref="IMacro"/> /// </summary> /// <param name="macro"><see cref="IMacro"/> to save</param> /// <param name="userId">Optional Id of the user deleting the macro</param> public void Save(IMacro macro, int userId = Cms.Core.Constants.Security.SuperUserId) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new MacroSavingNotification(macro, eventMessages); if (scope.Notifications.PublishCancelable(savingNotification)) { scope.Complete(); return; } if (string.IsNullOrWhiteSpace(macro.Name)) { throw new ArgumentException("Cannot save macro with empty name."); } _macroRepository.Save(macro); scope.Notifications.Publish(new MacroSavedNotification(macro, eventMessages).WithStateFrom(savingNotification)); Audit(AuditType.Save, userId, -1); scope.Complete(); } }
/// <summary> /// Saves an <see cref="IMacro"/> /// </summary> /// <param name="macro"><see cref="IMacro"/> to save</param> /// <param name="userId">Optional Id of the user deleting the macro</param> public void Save(IMacro macro, int userId = Constants.Security.SuperUserId) { using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IMacro>(macro); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) { scope.Complete(); return; } if (string.IsNullOrWhiteSpace(macro.Name)) { throw new ArgumentException("Cannot save macro with empty name."); } _macroRepository.Save(macro); saveEventArgs.CanCancel = false; scope.Events.Dispatch(Saved, this, saveEventArgs); Audit(AuditType.Save, userId, -1); scope.Complete(); } }