fix(files): report success cancellation and errors with safe next actions (U02)
This commit is contained in:
@@ -17,9 +17,9 @@ public partial class Dashboard
|
||||
private int? selectedYear = DateTime.Now.Year;
|
||||
private List<int> availableYears = [];
|
||||
private string clubName = string.Empty;
|
||||
private string? operationMessage;
|
||||
private string operationMessageClass = "alert-info";
|
||||
private string? savedPdfPath;
|
||||
private FileOperationResult? fileResult;
|
||||
private bool fileBusy;
|
||||
private string currentTheme = "light";
|
||||
|
||||
#endregion
|
||||
@@ -100,11 +100,16 @@ public partial class Dashboard
|
||||
|
||||
private async Task HandleBackupAsync()
|
||||
{
|
||||
var message = await BackupService.CreateBackupAsync();
|
||||
if (message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase))
|
||||
if (fileBusy) return;
|
||||
fileBusy = true;
|
||||
fileResult = null;
|
||||
try
|
||||
{
|
||||
SetOperationMessage(message, false);
|
||||
fileResult = await BackupService.CreateBackupAsync();
|
||||
|
||||
}
|
||||
catch (Exception ex) { fileResult = FileOperationResult.Error(ex); }
|
||||
finally { fileBusy = false; }
|
||||
}
|
||||
|
||||
private Task HandleRestoreAsync()
|
||||
@@ -120,25 +125,36 @@ public partial class Dashboard
|
||||
|
||||
private async Task HandleConfirmRestore()
|
||||
{
|
||||
showRestoreConfirm = false;
|
||||
var message = await BackupService.RestoreBackupAsync();
|
||||
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
|
||||
if (fileBusy) return;
|
||||
fileBusy = true;
|
||||
fileResult = null;
|
||||
try
|
||||
{
|
||||
showRestoreConfirm = false;
|
||||
fileResult = await BackupService.RestoreBackupAsync();
|
||||
if (fileResult.Status == FileOperationStatus.Success) await LoadAll();
|
||||
|
||||
if (isSuccess)
|
||||
{
|
||||
NavigationManager.NavigateTo("/", forceLoad: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetOperationMessage(message, isSuccess);
|
||||
}
|
||||
catch (Exception ex) { fileResult = FileOperationResult.Error(ex); }
|
||||
finally { fileBusy = false; }
|
||||
}
|
||||
|
||||
private async Task HandleDashboardExportAsync()
|
||||
{
|
||||
if (fileBusy) return;
|
||||
fileBusy = true;
|
||||
fileResult = null;
|
||||
try
|
||||
{
|
||||
var pdf = await PdfStatementService.GenerateDashboardStatementAsync(selectedYear);
|
||||
var suffix = selectedYear.HasValue ? $"_{selectedYear.Value}" : "_Gesamt";
|
||||
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht{suffix}.pdf");
|
||||
fileResult = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht{suffix}.pdf");
|
||||
|
||||
savedPdfPath = fileResult.Status == FileOperationStatus.Success ? fileResult.Path : null;
|
||||
|
||||
}
|
||||
catch (Exception ex) { fileResult = FileOperationResult.Error(ex); }
|
||||
finally { fileBusy = false; }
|
||||
}
|
||||
|
||||
private void OpenYearFilterDialog()
|
||||
@@ -160,12 +176,21 @@ public partial class Dashboard
|
||||
|
||||
private async Task HandleOpenSavedPdf()
|
||||
{
|
||||
if (fileBusy) return;
|
||||
fileBusy = true;
|
||||
fileResult = null;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(savedPdfPath))
|
||||
{
|
||||
await FileSaveService.OpenFileAsync(savedPdfPath);
|
||||
fileResult = await FileSaveService.OpenFileAsync(savedPdfPath);
|
||||
}
|
||||
|
||||
savedPdfPath = null;
|
||||
|
||||
}
|
||||
catch (Exception ex) { fileResult = FileOperationResult.Error(ex); }
|
||||
finally { fileBusy = false; }
|
||||
}
|
||||
|
||||
private void CancelOpenSavedPdf()
|
||||
@@ -177,12 +202,6 @@ public partial class Dashboard
|
||||
|
||||
#region Helpers
|
||||
|
||||
private void SetOperationMessage(string message, bool success)
|
||||
{
|
||||
operationMessage = message;
|
||||
operationMessageClass = success ? "alert-success" : "alert-danger";
|
||||
}
|
||||
|
||||
private static string FormatCurrency(decimal amount)
|
||||
{
|
||||
return amount.ToString("N2", CultureInfo.GetCultureInfo("de-DE")) + " €";
|
||||
|
||||
Reference in New Issue
Block a user