Fixed auto-export settings set up when importing a JSON file

This commit is contained in:
Thorsten Sommer 2023-01-22 21:38:47 +01:00
parent 639d501906
commit a868087af9
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -66,19 +66,29 @@ public static class Setup
// temporary database source by a JSON file. // temporary database source by a JSON file.
// //
//
// Enable the auto-export feature: // 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 }; //
if (await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_ENABLED) is { } autoExportEnabled)
autoExportEnabled.BoolValue = true; autoExportEnabled.BoolValue = true;
else
dbContext.Settings.Add(new Setting {Code = SettingNames.AUTO_EXPORT_ENABLED, BoolValue = true});
//
// Set the auto-export path and file: // 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 }; //
if(await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_DESTINATION_PATH) is { } autoExportPath)
autoExportPath.TextValue = Path.GetDirectoryName(path2JSONFile) ?? string.Empty; 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});
var autoExportFile = await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_FILENAME) ?? new Setting { Code = SettingNames.AUTO_EXPORT_FILENAME }; if(await dbContext.Settings.FirstOrDefaultAsync(n => n.Code == SettingNames.AUTO_EXPORT_FILENAME) is { } autoExportFile)
autoExportFile.TextValue = Path.GetFileName(path2JSONFile); 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: // 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, Code = SettingNames.AUTO_EXPORT_SENSITIVE_DATA,
BoolValue = false, BoolValue = false,