public async Task <IActionResult> GetShopeeFee() { var shopeeFeeSetting = await _appSettingService.GetAsync(AppSettingKey.ShopeeFee); int.TryParse(shopeeFeeSetting.Value, out int shopeeFee); return(Json(shopeeFee)); }
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()); }
public async Task <ActionResult> PostAsync([FromBody] AppSettings item) { if (!ModelState.IsValid) { return(BadRequest()); } try { var exist = await service.GetAsync(x => x.appname == item.appname); if (exist != null) { return(Conflict(new Response() { Status = false, Description = "Duplicate record" })); } var result = await service.AddAsync(item); if (result) { var newitem = await service.GetAsync(x => x.appname == item.appname); return(StatusCode(201, newitem)); } else { return(BadRequest()); } } catch (Exception ex) { logger.LogError(ex.Message); return(StatusCode(500, new Response() { Status = false, Description = "System error" })); } }