Add infrastructure layer with persistence and services

- EF Core DbContext and entity configurations
- Design-time factory for migrations
- Initial and soft-delete migrations
- Service implementations: Account, AccountYear, Entry,
  BalanceQuery, FileSave, PdfStatement
- Dependency injection registration
This commit is contained in:
2026-03-31 17:12:57 +02:00
parent 8fbb8b8ea2
commit c3d68020d5
19 changed files with 1450 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using Duempelkas.App.Services;
namespace Duempelkas.Infrastructure.Services;
public class FileSaveService : IFileSaveService
{
public async Task<string?> SaveFileAsync(byte[] content, string suggestedFileName)
{
var filePath = await ShowSaveDialogAsync(suggestedFileName);
if (filePath == null) return null;
await File.WriteAllBytesAsync(filePath, content);
return filePath;
}
private static Task<string?> ShowSaveDialogAsync(string suggestedFileName)
{
return Task.Run(() =>
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Fallback: save to Documents folder
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
return Path.Combine(documentsPath, suggestedFileName);
}
var extension = Path.GetExtension(suggestedFileName);
var filterName = extension == ".pdf" ? "PDF-Dateien" : "Dateien";
var filter = $"{filterName} (*{extension})|*{extension}|Alle Dateien (*.*)|*.*";
var script = $@"
Add-Type -AssemblyName System.Windows.Forms
$dialog = New-Object System.Windows.Forms.SaveFileDialog
$dialog.Filter = '{filter}'
$dialog.FileName = '{suggestedFileName.Replace("'", "''")}'
$dialog.Title = 'Datei speichern'
if ($dialog.ShowDialog() -eq 'OK') {{ $dialog.FileName }} else {{ '' }}
";
var psi = new ProcessStartInfo
{
FileName = "powershell",
Arguments = $"-NoProfile -Command \"{script.Replace("\"", "\\\"\"")}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = Process.Start(psi);
if (process == null) return null;
var result = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit();
return string.IsNullOrWhiteSpace(result) ? null : result;
});
}
}