Beispiel #1
0
        public async Task <ApiData> UpdateAppSetting([Required] string?settingName, SetAppSettingArgs args)
        {
            settingName = settingName?.Trim();
            if (string.IsNullOrEmpty(settingName))
            {
                throw new InvalidOperationException("参数名不能为空。");
            }
            var setting = await _appSettingService.GetAsync(settingName);

            if (setting == null)
            {
                throw new InvalidOperationException("参数不存在");
            }

            var prevValue = setting.SettingValue;

            switch (setting.SettingType)
            {
            case AppSettingTypes.字符串:
                await _appSettingService.SetStringAsync(settingName, args.SettingValue);

                break;

            case AppSettingTypes.布尔:
                await _appSettingService.SetBooleanAsync(settingName, Convert.ToBoolean(args.SettingValue));

                break;

            case AppSettingTypes.数字:
                await _appSettingService.SetNumberAsync(settingName, Convert.ToDecimal(args.SettingValue));

                break;

            default:
                break;
            }

            _logger.Information("将参数 {settingName} 的值由 {prevValue} 改为 {value}", settingName, prevValue, args.SettingValue);
            await _opHelper.SaveOpAsync($"参数名 {settingName},前值 {prevValue},新值 {args.SettingValue}", settingName, prevValue, args.SettingValue);

            return(this.Success());
        }