From 9f0d6641055fad0442041cc63021f7c1ca980e55 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Sun, 22 Jan 2023 21:06:34 +0100 Subject: [PATCH] Ensured that auto-export settings are available --- I18N Commander/DataModel/Setup.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/I18N Commander/DataModel/Setup.cs b/I18N Commander/DataModel/Setup.cs index c8c8ed5..5ec56c1 100644 --- a/I18N Commander/DataModel/Setup.cs +++ b/I18N Commander/DataModel/Setup.cs @@ -67,16 +67,23 @@ public static class Setup // // Enable the auto-export feature: - var autoExportEnabled = await dbContext.Settings.FirstAsync(n => n.Code == SettingNames.AUTO_EXPORT_ENABLED); + var autoExportEnabled = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_ENABLED) ?? new Setting { Code = SettingNames.AUTO_EXPORT_ENABLED }; autoExportEnabled.BoolValue = true; // Set the auto-export path and file: - var autoExportPath = await dbContext.Settings.FirstAsync(n => n.Code == SettingNames.AUTO_EXPORT_DESTINATION_PATH); + 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.FirstAsync(n => n.Code == SettingNames.AUTO_EXPORT_FILENAME); + 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); + // 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 + { + Code = SettingNames.AUTO_EXPORT_SENSITIVE_DATA, + BoolValue = false, + }; + // Save the changes: await dbContext.SaveChangesAsync(); }