Fixed culture code handling

This commit is contained in:
Thorsten Sommer 2022-07-31 21:19:13 +02:00
parent c9bd1b5be9
commit a47b18b7a8
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -233,7 +233,7 @@ public static class AppSettings
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
// Count the number of cultures:
var count = await db.Settings.CountAsync(n => n.Code == SettingNames.CULTURE);
var count = await db.Settings.CountAsync(n => n.Code.StartsWith(SettingNames.CULTURE));
// We have at least one default culture:
if(count == 0)
@ -263,7 +263,7 @@ public static class AppSettings
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
// Get the culture code:
var code = await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.CULTURE && n.IntegerValue == index);
var code = await db.Settings.FirstOrDefaultAsync(n => n.Code.StartsWith(SettingNames.CULTURE) && n.IntegerValue == index);
// When the culture code is not set & index = 1, use the default culture en-US:
if(code is null && index == 1)
@ -291,7 +291,7 @@ public static class AppSettings
await using var db = ProcessorMeta.ServiceProvider.GetRequiredService<DataContext>();
// Check, if the setting is already set:
if (await db.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.CULTURE && n.IntegerValue == index) is {} existingSetting)
if (await db.Settings.FirstOrDefaultAsync(n => n.Code.StartsWith(SettingNames.CULTURE) && n.IntegerValue == index) is {} existingSetting)
{
existingSetting.TextValue = code;
await db.SaveChangesAsync();
@ -302,7 +302,7 @@ public static class AppSettings
{
var setting = new Setting
{
Code = SettingNames.CULTURE,
Code = $"{SettingNames.CULTURE} {index}",
IntegerValue = index,
TextValue = code,
};