Added DeepL action setting
This commit is contained in:
7 files changed
+118
No files matched your search
@@ -113,4 +113,59 @@ public static class AppSettings
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DeepL Action
|
||||
|
||||
public static async Task SetDeepLAction(SettingDeepLAction action)
|
||||
{
|
||||
// Convert the enum to its int value:
|
||||
var intValue = (int)action;
|
||||
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_ACTION) is {} existingSetting)
|
||||
{
|
||||
existingSetting.IntegerValue = intValue;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
// Does not exist, so create it:
|
||||
else
|
||||
{
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.DEEPL_ACTION,
|
||||
IntegerValue = intValue,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<SettingDeepLAction> GetDeepLAction()
|
||||
{
|
||||
// Get the database:
|
||||
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
|
||||
|
||||
// Check, if the setting is already set:
|
||||
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.DEEPL_ACTION) is { } existingSetting)
|
||||
return (SettingDeepLAction) existingSetting.IntegerValue;
|
||||
|
||||
// Does not exist, so create it:
|
||||
var setting = new Setting
|
||||
{
|
||||
Code = SettingNames.DEEPL_ACTION,
|
||||
IntegerValue = (int)SettingDeepLAction.MANUAL,
|
||||
};
|
||||
|
||||
await db.Settings.AddAsync(setting);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return (SettingDeepLAction) setting.IntegerValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user