feat(usability): explain deleted bookings and linked transfer undo (U10)

This commit is contained in:
2026-11-02 19:26:23 +01:00
parent 2d36ab0b88
commit 1686f5769c
11 changed files with 146 additions and 14 deletions
@@ -30,6 +30,8 @@ public partial class AccountDetail
private int? selectedYear { get => Period.Year; set => Period.Year = value; }
private List<int> availableYears = [];
private bool entryActionBusy;
private Guid? undoToastId;
private int? confirmDeleteEntryId;
private string? confirmDeleteEntryTitle;
@@ -144,19 +146,27 @@ public partial class AccountDetail
private void CancelDeleteConfirm()
{
if (entryActionBusy) return;
confirmDeleteEntryId = null;
confirmDeleteEntryTitle = null;
}
private async Task HandleConfirmDelete()
{
if (confirmDeleteEntryId.HasValue)
if (entryActionBusy || !confirmDeleteEntryId.HasValue) return;
entryActionBusy = true;
try
{
await EntryService.DeleteEntryAsync(confirmDeleteEntryId.Value);
var id = confirmDeleteEntryId.Value;
await EntryService.DeleteEntryAsync(id);
confirmDeleteEntryId = null;
confirmDeleteEntryTitle = null;
await LoadAll();
if (undoToastId.HasValue) Toasts.Dismiss(undoToastId.Value);
undoToastId = Toasts.Show("Buchung gelöscht.", ToastKind.Success,
actionLabel: "Rückgängig", action: () => UndoEntryChange(id, true));
}
catch (Exception ex) { Toasts.Show("Die Buchung konnte nicht geändert werden. Bitte erneut versuchen.", ToastKind.Error, ex.Message); }
finally { entryActionBusy = false; }
}
private void RequestRestoreEntry(int entryId)
@@ -167,19 +177,57 @@ public partial class AccountDetail
private void CancelRestoreConfirm()
{
if (entryActionBusy) return;
confirmRestoreEntryId = null;
confirmRestoreEntryTitle = null;
}
private async Task HandleConfirmRestore()
{
if (confirmRestoreEntryId.HasValue)
if (entryActionBusy || !confirmRestoreEntryId.HasValue) return;
entryActionBusy = true;
try
{
await EntryService.RestoreEntryAsync(confirmRestoreEntryId.Value);
var id = confirmRestoreEntryId.Value;
await EntryService.RestoreEntryAsync(id);
confirmRestoreEntryId = null;
confirmRestoreEntryTitle = null;
await LoadAll();
if (undoToastId.HasValue) Toasts.Dismiss(undoToastId.Value);
undoToastId = Toasts.Show("Buchung wiederhergestellt.", ToastKind.Success,
actionLabel: "Rückgängig", action: () => UndoEntryChange(id, false));
}
catch (Exception ex) { Toasts.Show("Die Buchung konnte nicht geändert werden. Bitte erneut versuchen.", ToastKind.Error, ex.Message); }
finally { entryActionBusy = false; }
}
private async Task UndoEntryChange(int id, bool restore)
{
if (entryActionBusy) return;
entryActionBusy = true;
try
{
var current = (await EntryService.GetEntriesAsync(AccountId, (int?)null)).FirstOrDefault(e => e.Id == id);
if (current == null || current.IsDeleted != restore)
{
Toasts.Show("Die Buchung wurde inzwischen geändert. Bitte die aktuelle Liste prüfen.");
return;
}
if (restore) await EntryService.RestoreEntryAsync(id); else await EntryService.DeleteEntryAsync(id);
if (undoToastId.HasValue) Toasts.Dismiss(undoToastId.Value);
await LoadAll();
Toasts.Show("Änderung rückgängig gemacht.", ToastKind.Success);
}
finally { entryActionBusy = false; }
}
private string EntryChangeMessage(int? id, bool restore)
{
var entry = entries?.FirstOrDefault(e => e.Id == id);
if (entry == null) return "Bitte die aktuelle Buchung prüfen.";
var description = $"{entry.Date:dd.MM.yyyy}, {entry.Title}, {FormatAmount(entry.Amount)}, Konto {account?.Name}.";
return description + (entry.IsTransfer
? $" Diese Umbuchung betrifft {account?.Name} und {entry.LinkedAccountName}. Die Buchungen auf beiden Konten werden gemeinsam {(restore ? "wiederhergestellt und wieder mitgerechnet" : "gelöscht und nicht mehr mitgerechnet")}."
: $" Die Buchung wird {(restore ? "wiederhergestellt und wieder mitgerechnet" : "gelöscht und nicht mehr mitgerechnet") }.");
}
private void RequestEditEntry(int entryId)