/// <summary> /// Saves an <see cref="IDataType"/> /// </summary> /// <param name="dataType"><see cref="IDataType"/> to save</param> /// <param name="userId">Id of the user issuing the save</param> public void Save(IDataType dataType, int userId = Constants.Security.SuperUserId) { dataType.CreatorId = userId; using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IDataType>(dataType); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) { scope.Complete(); return; } if (string.IsNullOrWhiteSpace(dataType.Name)) { throw new ArgumentException("Cannot save datatype with empty name."); } if (dataType.Name != null && dataType.Name.Length > 255) { throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } _dataTypeRepository.Save(dataType); saveEventArgs.CanCancel = false; scope.Events.Dispatch(Saved, this, saveEventArgs); Audit(AuditType.Save, userId, dataType.Id); scope.Complete(); } }
/// <summary> /// Saves an <see cref="IDataType"/> /// </summary> /// <param name="dataType"><see cref="IDataType"/> to save</param> /// <param name="userId">Id of the user issuing the save</param> public void Save(IDataType dataType, int userId = Cms.Core.Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); dataType.CreatorId = userId; using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IDataType>(dataType); var savingDataTypeNotification = new DataTypeSavingNotification(dataType, evtMsgs); if (scope.Notifications.PublishCancelable(savingDataTypeNotification)) { scope.Complete(); return; } if (string.IsNullOrWhiteSpace(dataType.Name)) { throw new ArgumentException("Cannot save datatype with empty name."); } if (dataType.Name != null && dataType.Name.Length > 255) { throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } _dataTypeRepository.Save(dataType); scope.Notifications.Publish(new DataTypeSavedNotification(dataType, evtMsgs).WithStateFrom(savingDataTypeNotification)); Audit(AuditType.Save, userId, dataType.Id); scope.Complete(); } }
/// <summary> /// Saves an <see cref="IDataType"/> /// </summary> /// <param name="dataType"><see cref="IDataType"/> to save</param> /// <param name="userId">Id of the user issueing the save</param> public void Save(IDataType dataType, int userId = 0) { dataType.CreatorId = userId; using (var scope = ScopeProvider.CreateScope()) { var saveEventArgs = new SaveEventArgs <IDataType>(dataType); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) { scope.Complete(); return; } if (string.IsNullOrWhiteSpace(dataType.Name)) { throw new ArgumentException("Cannot save datatype with empty name."); } _dataTypeRepository.Save(dataType); saveEventArgs.CanCancel = false; scope.Events.Dispatch(Saved, this, saveEventArgs); Audit(AuditType.Save, userId, dataType.Id); scope.Complete(); } }