Exemple #1
0
        public async Task <CommandResult> Handle(UpdateConfigurationFromEditorCommand command)
        {
            var instance = await configurationService.GetAsync(command.ConfigurationType, command.Identity);

            var            configSetModel = configSetRegistry.GetConfigSetForConfig(command.ConfigurationType);
            ConfigInstance updatedInstance;

            try
            {
                updatedInstance = await configurationUpdatePayloadMapper.UpdateConfigurationInstance(instance, command.ConfigurationAsJson, configSetModel);
            }
            catch (ConfigModelParsingException ex)
            {
                return(CommandResult.Failure(ex.Message));
            }
            var validationResult = await validator.Validate(updatedInstance.GetConfiguration(), configSetModel.Get(command.ConfigurationType), command.Identity);

            if (!validationResult.IsValid)
            {
                return(CommandResult.Failure(string.Join(Environment.NewLine, validationResult.Errors)));
            }
            await configRepository.UpdateConfigAsync(updatedInstance);

            await eventService.Publish(new ConfigurationUpdatedEvent(updatedInstance));

            return(CommandResult.Success());
        }
 private ConfigurationSetModel GetConfigurationSetForModel(ConfigInstance configInstance)
 {
     return(configCollection.GetConfigSetForConfig(configInstance.ConfigType));
 }