Exemplo n.º 1
0
        /// <summary>
        /// Saves a collection of <see cref="IDataType"/>
        /// </summary>
        /// <param name="dataTypeDefinitions"><see cref="IDataType"/> to save</param>
        /// <param name="userId">Id of the user issuing the save</param>
        public void Save(IEnumerable <IDataType> dataTypeDefinitions, int userId)
        {
            var evtMsgs = EventMessagesFactory.Get();
            var dataTypeDefinitionsA = dataTypeDefinitions.ToArray();

            using (var scope = ScopeProvider.CreateScope())
            {
                var savingDataTypeNotification = new DataTypeSavingNotification(dataTypeDefinitions, evtMsgs);
                if (scope.Notifications.PublishCancelable(savingDataTypeNotification))
                {
                    scope.Complete();
                    return;
                }

                foreach (var dataTypeDefinition in dataTypeDefinitionsA)
                {
                    dataTypeDefinition.CreatorId = userId;
                    _dataTypeRepository.Save(dataTypeDefinition);
                }

                scope.Notifications.Publish(new DataTypeSavedNotification(dataTypeDefinitions, evtMsgs).WithStateFrom(savingDataTypeNotification));

                Audit(AuditType.Save, userId, -1);

                scope.Complete();
            }
        }
Exemplo n.º 2
0
        /// <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();
            }
        }