Esempio n. 1
0
        private void InitFields(IEnumerable <FieldDefinition> fields)
        {
            foreach (var item in fields)
            {
                if (IsAlreadyExecuted <FieldDefinition>(item.Id, item.AreaType.Name))
                {
                    continue;
                }

                var currentField = _fieldDefinitionService.Get(item.AreaType, item.Id);
                if (currentField == null)
                {
                    _fieldFrameworkSetupLocalizationService.Localize(item);
                    _fieldDefinitionService.Create(item);
                    SetAlreadyExecuted <FieldDefinition>(item.Id, item.AreaType.Name);
                    continue;
                }

                if (item.FieldType != currentField.FieldType)
                {
                    _logger.LogError("Accelerator \"{Id}\" field with \"{FieldType}\" type can't be created. The system already has the \"{CurrentId}\" field with \"{CurrentFieldType}\" type. Accelerator deployment would fail.", item.Id, item.FieldType, currentField.Id, currentField.FieldType);
                    _settingService.Set <bool?>("Accelerator.DefinitionsError", true);
                    continue;
                }
                if (item.MultiCulture != currentField.MultiCulture)
                {
                    _logger.LogError("Accelerator \"{Id}\" field with \"MultiCulture\" setting and \"{MultiCulture}\" value can't be created. The system already has the \"{CurrentId}\" field with \"MultiCulture\" setting and \"{CurrentMultiCulture}\" value. Accelerator deployment would fail.", item.Id, item.MultiCulture, currentField.Id, currentField.MultiCulture);
                    _settingService.Set <bool?>("Accelerator.DefinitionsError", true);
                    continue;
                }

                SetAlreadyExecuted <FieldDefinition>(item.Id, item.AreaType.Name);
            }
        }
        private void InitFields()
        {
            var items = new[]
            {
                new FieldDefinition(SmartImageService.FieldName, SystemFieldTypeConstants.Text)
                {
                    CanBeGridColumn = true,
                    CanBeGridFilter = true,
                    Localizations   =
                    {
                        ["sv-SE"] = { Name = "Smart Image Tags" },
                        ["en-US"] = { Name = "Smart Image Tags" },
                    }
                },
            };

            foreach (var item in items)
            {
                var currentField = _fieldDefinitionService.Get(item.Id);
                if (currentField != null)
                {
                    continue;
                }
                _fieldDefinitionService.Create(item);
            }
        }
Esempio n. 3
0
        private FieldDefinition GetAreaFieldDefinition <T>(string textOptionName, bool isMultiCulture) where T : IArea
        {
            var textOptionField = _fieldDefinitionService.Get <T>(textOptionName)?.MakeWritableClone();

            if (textOptionField != null)
            {
                if (textOptionField.MultiCulture != isMultiCulture)
                {
                    throw new Exception($"A Text Option with ID: {textOptionField.Id} exists. It's not possible to change To or From Multi Culture.");
                }

                return(textOptionField);
            }

            _fieldDefinitionService.Create(new FieldDefinition <T>(textOptionName, SystemFieldTypeConstants.TextOption)
            {
                Localizations =
                {
                    ["sv-SE"] = { Name = textOptionName },
                    ["en-US"] = { Name = textOptionName }
                },
                CanBeGridColumn = true,
                CanBeGridFilter = true,
                MultiCulture    = isMultiCulture,
                Option          = new TextOption
                {
                    MultiSelect = false
                }
            });

            textOptionField = _fieldDefinitionService.Get <T>(textOptionName).MakeWritableClone();

            return(textOptionField);
        }
Esempio n. 4
0
        private FieldDefinition CreateField(FieldDefinition fieldDefinition)
        {
            var currentField = _fieldDefinitionService.Get<ProductArea>(fieldDefinition.Id);
            if (currentField != null)
            {
                // Update options of the field even if the field already exists
                if (fieldDefinition.Option != null)
                {
                    currentField = currentField.MakeWritableClone();
                    currentField.Option = fieldDefinition.Option;
                    _fieldDefinitionService.Update(currentField);
                }

                return currentField;
            }

            _fieldDefinitionService.Create(fieldDefinition);
            return _fieldDefinitionService.Get<ProductArea>(fieldDefinition.Id);
        }