41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
|
|
using Apimanager_backend.Data;
|
|
using Apimanager_backend.Exceptions;
|
|
using Apimanager_backend.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Apimanager_backend.Services
|
|
{
|
|
public class SystemConfigService : ISystemConfigService
|
|
{
|
|
private readonly ApiContext apiContext;
|
|
private readonly ILogger<SystemConfigService> logger;
|
|
public SystemConfigService(ApiContext apiContext,ILogger<SystemConfigService> logger)
|
|
{
|
|
this.apiContext = apiContext;
|
|
this.logger = logger;
|
|
}
|
|
public async Task<SystemConfig> UpdateSystemConfig(string configName, string configBody)
|
|
{
|
|
var config = await apiContext.SystemConfigs.FirstOrDefaultAsync(x => x.ConfigName == configName);
|
|
if (config == null)
|
|
{
|
|
throw new BaseException(5006,"配置不存在");
|
|
}
|
|
config.ConfigBody = configBody;
|
|
apiContext.SystemConfigs.Update(config);
|
|
await apiContext.SaveChangesAsync();
|
|
return config;
|
|
}
|
|
public async Task<SystemConfig> GetSystemConfig(string configName)
|
|
{
|
|
var config = await apiContext.SystemConfigs.FirstOrDefaultAsync(x => x.ConfigName == configName);
|
|
if (config == null)
|
|
{
|
|
throw new BaseException(5006, "配置不存在");
|
|
}
|
|
return config;
|
|
}
|
|
}
|
|
}
|