Added DeepL action setting

This commit is contained in:
tsommer committed 2022-07-30 16:38:38 +02:00
1 parent 9cd735ad5c
commit c211c9ef62
7 files changed
+118

No files matched your search

+55
View File
@@ -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
}