Beispiel #1
0
        public DataTypeDisplay PostSave(DataTypeSave dataType)
        {
            //If we've made it here, then everything has been wired up and validated by the attribute

            // TODO: Check if the property editor has changed, if it has ensure we don't pass the
            // existing values to the new property editor!

            // get the current configuration,
            // get the new configuration as a dictionary (this is how we get it from model)
            // and map to an actual configuration object
            var currentConfiguration    = dataType.PersistedDataType.Configuration;
            var configurationDictionary = dataType.ConfigurationFields.ToDictionary(x => x.Key, x => x.Value);
            var configuration           = dataType.PropertyEditor.GetConfigurationEditor().FromConfigurationEditor(configurationDictionary, currentConfiguration);

            dataType.PersistedDataType.Configuration = configuration;

            // save the data type
            try
            {
                Services.DataTypeService.Save(dataType.PersistedDataType, Security.CurrentUser.Id);
            }
            catch (DuplicateNameException ex)
            {
                ModelState.AddModelError("Name", ex.Message);
                throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
            }

            // map back to display model, and return
            var display = Mapper.Map <IDataType, DataTypeDisplay>(dataType.PersistedDataType);

            display.AddSuccessNotification(Services.TextService.Localize("speechBubbles/dataTypeSaved"), "");
            return(display);
        }
Beispiel #2
0
 // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate
 // Umbraco.Code.MapAll -Key -Path -CreatorId -Level -SortOrder -Configuration
 private void Map(DataTypeSave source, IDataType target, MapperContext context)
 {
     target.DatabaseType = MapDatabaseType(source);
     target.Editor       = _propertyEditors[source.EditorAlias];
     target.Id           = Convert.ToInt32(source.Id);
     target.Name         = source.Name;
     target.ParentId     = source.ParentId;
 }
Beispiel #3
0
        private ValueStorageType MapDatabaseType(DataTypeSave source)
        {
            if (!_propertyEditors.TryGet(source.EditorAlias, out var editor))
            {
                throw new InvalidOperationException($"Could not find property editor \"{source.EditorAlias}\".");
            }

            // TODO: what about source.PropertyEditor? can we get the configuration here? 'cos it may change the storage type?!
            var valueType = editor.GetValueEditor().ValueType;

            return(ValueTypes.ToStorageType(valueType));
        }
        public ActionResult <DataTypeDisplay?> PostSave(DataTypeSave dataType)
        {
            //If we've made it here, then everything has been wired up and validated by the attribute

            // TODO: Check if the property editor has changed, if it has ensure we don't pass the
            // existing values to the new property editor!

            // get the current configuration,
            // get the new configuration as a dictionary (this is how we get it from model)
            // and map to an actual configuration object
            var currentConfiguration    = dataType.PersistedDataType?.Configuration;
            var configurationDictionary = dataType.ConfigurationFields?.ToDictionary(x => x.Key, x => x.Value);
            var configuration           = dataType.PropertyEditor?.GetConfigurationEditor().FromConfigurationEditor(configurationDictionary, currentConfiguration);

            if (dataType.PersistedDataType is not null)
            {
                dataType.PersistedDataType.Configuration = configuration;
            }

            var currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser;

            // save the data type
            try
            {
                if (dataType.PersistedDataType is not null)
                {
                    _dataTypeService.Save(dataType.PersistedDataType, currentUser?.Id ?? -1);
                }
            }
            catch (DuplicateNameException ex)
            {
                ModelState.AddModelError("Name", ex.Message);
                return(ValidationProblem(ModelState));
            }

            // map back to display model, and return
            var display = _umbracoMapper.Map <IDataType, DataTypeDisplay>(dataType.PersistedDataType);

            display?.AddSuccessNotification(_localizedTextService.Localize("speechBubbles", "dataTypeSaved"), "");
            return(display);
        }
Beispiel #5
0
        public DataTypeDisplay PostSave(DataTypeSave dataType)
        {
            //If we've made it here, then everything has been wired up and validated by the attribute

            //finally we need to save the data type and it's pre-vals
            var dtService = ApplicationContext.Services.DataTypeService;

            //TODO: Check if the property editor has changed, if it has ensure we don't pass the
            // existing values to the new property editor!

            //get the prevalues, current and new
            var preValDictionary = dataType.PreValues.ToDictionary(x => x.Key, x => x.Value);
            var currVal          = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataType.PersistedDataType.Id);

            //we need to allow for the property editor to deserialize the prevalues
            var formattedVal = dataType.PropertyEditor.PreValueEditor.ConvertEditorToDb(
                preValDictionary,
                currVal);

            try
            {
                //save the data type
                dtService.SaveDataTypeAndPreValues(dataType.PersistedDataType, formattedVal, (int)Security.CurrentUser.Id);
            }
            catch (DuplicateNameException ex)
            {
                ModelState.AddModelError("Name", ex.Message);
                throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
            }

            var display = Mapper.Map <IDataTypeDefinition, DataTypeDisplay>(dataType.PersistedDataType);

            display.AddSuccessNotification(ui.Text("speechBubbles", "dataTypeSaved"), "");

            //now return the updated model
            return(display);
        }