From a868087af9f954804b71c0ac69370e00c0b956dc Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 22 Jan 2023 21:38:47 +0100 Subject: [PATCH] Fixed auto-export settings set up when importing a JSON file --- I18N Commander/DataModel/Setup.cs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/I18N Commander/DataModel/Setup.cs b/I18N Commander/DataModel/Setup.cs index 5ec56c1..ebbd986 100644 --- a/I18N Commander/DataModel/Setup.cs +++ b/I18N Commander/DataModel/Setup.cs @@ -66,19 +66,29 @@ public static class Setup // temporary database source by a JSON file. // + // // Enable the auto-export feature: - var autoExportEnabled = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_ENABLED) ?? new Setting { Code = SettingNames.AUTO_EXPORT_ENABLED }; - autoExportEnabled.BoolValue = true; - + // + if (await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_ENABLED) is { } autoExportEnabled) + autoExportEnabled.BoolValue = true; + else + dbContext.Settings.Add(new Setting {Code = SettingNames.AUTO_EXPORT_ENABLED, BoolValue = true}); + + // // Set the auto-export path and file: - var autoExportPath = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_DESTINATION_PATH) ?? new Setting { Code = SettingNames.AUTO_EXPORT_DESTINATION_PATH }; - autoExportPath.TextValue = Path.GetDirectoryName(path2JSONFile) ?? string.Empty; - - var autoExportFile = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_FILENAME) ?? new Setting { Code = SettingNames.AUTO_EXPORT_FILENAME }; - autoExportFile.TextValue = Path.GetFileName(path2JSONFile); - + // + if(await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_DESTINATION_PATH) is { } autoExportPath) + autoExportPath.TextValue = Path.GetDirectoryName(path2JSONFile) ?? string.Empty; + else + dbContext.Settings.Add(new Setting {Code = SettingNames.AUTO_EXPORT_DESTINATION_PATH, TextValue = Path.GetDirectoryName(path2JSONFile) ?? string.Empty}); + + if(await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_FILENAME) is { } autoExportFile) + autoExportFile.TextValue = Path.GetFileName(path2JSONFile); + else + dbContext.Settings.Add(new Setting {Code = SettingNames.AUTO_EXPORT_FILENAME, TextValue = Path.GetFileName(path2JSONFile)}); + // Ensure that the sensitive data setting is present and disabled by default: - var autoExportSensitiveData = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_SENSITIVE_DATA) ?? new Setting + var _ = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_SENSITIVE_DATA) ?? new Setting { Code = SettingNames.AUTO_EXPORT_SENSITIVE_DATA, BoolValue = false,