refactor(app): move account razor inline code to partial classes

This commit is contained in:
2026-04-03 12:59:06 +02:00
parent 9807e4d61d
commit 55c2c01418
10 changed files with 294 additions and 181 deletions

View File

@@ -0,0 +1,194 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Pages.Accounts;
public partial class AccountDetail
{
#region Parameters
[Parameter]
public int AccountId { get; set; }
#endregion
#region Fields
private AccountSummaryDto? account;
private AccountBalanceDto? balance;
private List<EntryDto>? entries;
private bool showAddEntry;
private bool showAddTransfer;
private bool showEditName;
private bool showEditCarryover;
private bool showCurrentYearOnly = true;
private int? confirmDeleteEntryId;
private string? confirmDeleteEntryTitle;
private int? confirmRestoreEntryId;
private string? confirmRestoreEntryTitle;
private string? savedPdfPath;
private EntryDto? editingEntry;
private EntryDto? editingTransferEntry;
#endregion
#region Navigation
private void NavigateBack() => Navigation.NavigateTo("/");
#endregion
#region Lifecycle
protected override async Task OnParametersSetAsync()
{
await LoadAll();
}
#endregion
#region Data Loading
private async Task LoadAll()
{
account = await AccountService.GetAccountAsync(AccountId);
balance = await BalanceQueryService.GetAccountBalanceAsync(AccountId);
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
}
private async Task ToggleYearFilter()
{
showCurrentYearOnly = !showCurrentYearOnly;
entries = await EntryService.GetEntriesAsync(AccountId, showCurrentYearOnly);
}
#endregion
#region Actions
private async Task HandleSaveName(string newName)
{
await AccountService.RenameAccountAsync(AccountId, newName);
showEditName = false;
await LoadAll();
}
private async Task HandleSaveCarryover(decimal newAmount)
{
await AccountService.UpdateCarryoverAsync(AccountId, newAmount);
showEditCarryover = false;
await LoadAll();
}
private async Task HandleEntryCreated()
{
showAddEntry = false;
await LoadAll();
}
private async Task HandleTransferCreated()
{
showAddTransfer = false;
await LoadAll();
}
private void RequestDeleteEntry(int entryId)
{
confirmDeleteEntryId = entryId;
confirmDeleteEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
}
private void CancelDeleteConfirm()
{
confirmDeleteEntryId = null;
confirmDeleteEntryTitle = null;
}
private async Task HandleConfirmDelete()
{
if (confirmDeleteEntryId.HasValue)
{
await EntryService.DeleteEntryAsync(confirmDeleteEntryId.Value);
confirmDeleteEntryId = null;
confirmDeleteEntryTitle = null;
await LoadAll();
}
}
private void RequestRestoreEntry(int entryId)
{
confirmRestoreEntryId = entryId;
confirmRestoreEntryTitle = entries?.FirstOrDefault(e => e.Id == entryId)?.Title;
}
private void CancelRestoreConfirm()
{
confirmRestoreEntryId = null;
confirmRestoreEntryTitle = null;
}
private async Task HandleConfirmRestore()
{
if (confirmRestoreEntryId.HasValue)
{
await EntryService.RestoreEntryAsync(confirmRestoreEntryId.Value);
confirmRestoreEntryId = null;
confirmRestoreEntryTitle = null;
await LoadAll();
}
}
private void RequestEditEntry(int entryId)
{
var entry = entries?.FirstOrDefault(e => e.Id == entryId);
if (entry?.IsTransfer == true)
{
editingTransferEntry = entry;
}
else
{
editingEntry = entry;
}
}
private async Task HandleEntryEdited()
{
editingEntry = null;
editingTransferEntry = null;
await LoadAll();
}
private async Task HandleExport()
{
var pdf = await PdfStatementService.GenerateStatementAsync(AccountId, showCurrentYearOnly);
var suffix = showCurrentYearOnly ? $"_{DateTime.Now.Year}" : "_Gesamt";
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{account?.Name}{suffix}.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
}
#endregion
#region Helpers
private static string FormatAmount(decimal amount) => $"{amount:N2} €";
#endregion
}