Compare commits

..

3 Commits

28 changed files with 827 additions and 467 deletions

View File

@@ -9,8 +9,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public AccountSummaryDto Account { get; set; } = default!;
private void Navigate() => Navigation.NavigateTo($"/accounts/{Account.Id}");
}

View File

@@ -0,0 +1,20 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Accounts;
public partial class AccountCard
{
#region Parameters
[Parameter]
public AccountSummaryDto Account { get; set; } = default!;
#endregion
#region Actions
private void Navigate() => Navigation.NavigateTo($"/accounts/{Account.Id}");
#endregion
}

View File

@@ -7,6 +7,3 @@
} }
</div> </div>
@code {
[Parameter] public List<AccountSummaryDto> Accounts { get; set; } = new();
}

View File

@@ -0,0 +1,14 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Accounts;
public partial class AccountCardList
{
#region Parameters
[Parameter]
public List<AccountSummaryDto> Accounts { get; set; } = new();
#endregion
}

View File

@@ -34,17 +34,3 @@
</td> </td>
</tr> </tr>
@code {
[Parameter] public EntryDto Entry { get; set; } = default!;
[Parameter] public EventCallback<int> OnDelete { get; set; }
[Parameter] public EventCallback<int> OnRestore { get; set; }
[Parameter] public EventCallback<int> OnEdit { get; set; }
private string GetRowClass()
{
var classes = new List<string>();
if (Entry.IsTransfer) classes.Add("entry-row-transfer");
if (Entry.IsDeleted) classes.Add("entry-deleted");
return string.Join(" ", classes);
}
}

View File

@@ -0,0 +1,43 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Accounts;
public partial class EntryRow
{
#region Parameters
[Parameter]
public EntryDto Entry { get; set; } = default!;
[Parameter]
public EventCallback<int> OnDelete { get; set; }
[Parameter]
public EventCallback<int> OnRestore { get; set; }
[Parameter]
public EventCallback<int> OnEdit { get; set; }
#endregion
#region Helpers
private string GetRowClass()
{
var classes = new List<string>();
if (Entry.IsTransfer)
{
classes.Add("entry-row-transfer");
}
if (Entry.IsDeleted)
{
classes.Add("entry-deleted");
}
return string.Join(" ", classes);
}
#endregion
}

View File

@@ -23,9 +23,3 @@
<div class="text-center py-3 text-muted">Keine Buchungen vorhanden.</div> <div class="text-center py-3 text-muted">Keine Buchungen vorhanden.</div>
} }
@code {
[Parameter] public List<EntryDto> Entries { get; set; } = new();
[Parameter] public EventCallback<int> OnDeleteEntry { get; set; }
[Parameter] public EventCallback<int> OnRestoreEntry { get; set; }
[Parameter] public EventCallback<int> OnEditEntry { get; set; }
}

View File

@@ -0,0 +1,23 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Accounts;
public partial class EntryTable
{
#region Parameters
[Parameter]
public List<EntryDto> Entries { get; set; } = new();
[Parameter]
public EventCallback<int> OnDeleteEntry { get; set; }
[Parameter]
public EventCallback<int> OnRestoreEntry { get; set; }
[Parameter]
public EventCallback<int> OnEditEntry { get; set; }
#endregion
}

View File

@@ -13,17 +13,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public EventCallback<string> OnSave { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private string name = string.Empty;
private async Task Save()
{
if (!string.IsNullOrWhiteSpace(name))
await OnSave.InvokeAsync(name.Trim());
}
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,36 @@
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class AddAccountDialog
{
#region Parameters
[Parameter]
public EventCallback<string> OnSave { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Fields
private string name = string.Empty;
#endregion
#region Actions
private async Task Save()
{
if (!string.IsNullOrWhiteSpace(name))
{
await OnSave.InvokeAsync(name.Trim());
}
}
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -34,36 +34,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public int AccountId { get; set; }
[Parameter] public EntryDto? EditEntry { get; set; }
[Parameter] public EventCallback OnSave { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private EntryType entryType = EntryType.Income;
private DateTime date = DateTime.Today;
private string title = string.Empty;
private decimal amount;
protected override void OnParametersSet()
{
if (EditEntry != null)
{
entryType = EditEntry.Type;
date = EditEntry.Date;
title = EditEntry.Title;
amount = EditEntry.Amount;
}
}
private async Task Save()
{
if (EditEntry != null)
await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount);
else
await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount);
await OnSave.InvokeAsync();
}
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,68 @@
using Duempelkas.App.Services.Models;
using Duempelkas.Domain.Enums;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class AddEntryDialog
{
#region Parameters
[Parameter]
public int AccountId { get; set; }
[Parameter]
public EntryDto? EditEntry { get; set; }
[Parameter]
public EventCallback OnSave { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Fields
private EntryType entryType = EntryType.Income;
private DateTime date = DateTime.Today;
private string title = string.Empty;
private decimal amount;
#endregion
#region Lifecycle
protected override void OnParametersSet()
{
if (EditEntry != null)
{
entryType = EditEntry.Type;
date = EditEntry.Date;
title = EditEntry.Title;
amount = EditEntry.Amount;
}
}
#endregion
#region Actions
private async Task Save()
{
if (EditEntry != null)
{
await EntryService.UpdateEntryAsync(EditEntry.Id, date, title.Trim(), amount);
}
else
{
await EntryService.CreateEntryAsync(AccountId, entryType, date, title.Trim(), amount);
}
await OnSave.InvokeAsync();
}
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -33,42 +33,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public int SourceAccountId { get; set; }
[Parameter] public EntryDto? EditEntry { get; set; }
[Parameter] public EventCallback OnSave { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private List<AccountSummaryDto> accounts = new();
private int targetAccountId;
private DateTime date = DateTime.Today;
private string title = string.Empty;
private decimal amount;
private bool CanSave => targetAccountId > 0 && !string.IsNullOrWhiteSpace(title) && amount > 0;
protected override async Task OnParametersSetAsync()
{
if (!accounts.Any())
accounts = await AccountService.GetAllAccountsAsync();
if (EditEntry != null)
{
targetAccountId = EditEntry.LinkedAccountId ?? 0;
date = EditEntry.Date;
title = EditEntry.Title;
amount = EditEntry.Amount;
}
}
private async Task Save()
{
if (EditEntry != null)
await EntryService.UpdateTransferAsync(EditEntry.Id, targetAccountId, date, title.Trim(), amount);
else
await EntryService.CreateTransferAsync(SourceAccountId, targetAccountId, date, title.Trim(), amount);
await OnSave.InvokeAsync();
}
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,79 @@
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class AddTransferDialog
{
#region Parameters
[Parameter]
public int SourceAccountId { get; set; }
[Parameter]
public EntryDto? EditEntry { get; set; }
[Parameter]
public EventCallback OnSave { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Fields
private List<AccountSummaryDto> accounts = new();
private int targetAccountId;
private DateTime date = DateTime.Today;
private string title = string.Empty;
private decimal amount;
#endregion
#region Properties
private bool CanSave => targetAccountId > 0 && !string.IsNullOrWhiteSpace(title) && amount > 0;
#endregion
#region Lifecycle
protected override async Task OnParametersSetAsync()
{
if (!accounts.Any())
{
accounts = await AccountService.GetAllAccountsAsync();
}
if (EditEntry != null)
{
targetAccountId = EditEntry.LinkedAccountId ?? 0;
date = EditEntry.Date;
title = EditEntry.Title;
amount = EditEntry.Amount;
}
}
#endregion
#region Actions
private async Task Save()
{
if (EditEntry != null)
{
await EntryService.UpdateTransferAsync(EditEntry.Id, targetAccountId, date, title.Trim(), amount);
}
else
{
await EntryService.CreateTransferAsync(SourceAccountId, targetAccountId, date, title.Trim(), amount);
}
await OnSave.InvokeAsync();
}
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -9,16 +9,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public string Title { get; set; } = "Bestätigung";
[Parameter] public string Message { get; set; } = "Sind Sie sicher?";
[Parameter] public string ConfirmText { get; set; } = "Ja, bestätigen";
[Parameter] public string CancelText { get; set; } = "Nein, abbrechen";
[Parameter] public string ConfirmButtonClass { get; set; } = "btn btn-danger";
[Parameter] public string ConfirmIconClass { get; set; } = "bi bi-trash";
[Parameter] public EventCallback OnConfirm { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private async Task Confirm() => await OnConfirm.InvokeAsync();
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class ConfirmDialog
{
#region Parameters
[Parameter]
public string Title { get; set; } = "Bestätigung";
[Parameter]
public string Message { get; set; } = "Sind Sie sicher?";
[Parameter]
public string ConfirmText { get; set; } = "Ja, bestätigen";
[Parameter]
public string CancelText { get; set; } = "Nein, abbrechen";
[Parameter]
public string ConfirmButtonClass { get; set; } = "btn btn-danger";
[Parameter]
public string ConfirmIconClass { get; set; } = "bi bi-trash";
[Parameter]
public EventCallback OnConfirm { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Actions
private async Task Confirm() => await OnConfirm.InvokeAsync();
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -12,16 +12,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public decimal CurrentAmount { get; set; }
[Parameter] public EventCallback<decimal> OnSave { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private decimal amount;
protected override void OnParametersSet() => amount = CurrentAmount;
private async Task Save() => await OnSave.InvokeAsync(amount);
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class EditCarryoverDialog
{
#region Parameters
[Parameter]
public decimal CurrentAmount { get; set; }
[Parameter]
public EventCallback<decimal> OnSave { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Fields
private decimal amount;
#endregion
#region Lifecycle
protected override void OnParametersSet() => amount = CurrentAmount;
#endregion
#region Actions
private async Task Save() => await OnSave.InvokeAsync(amount);
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -12,22 +12,3 @@
</div> </div>
</div> </div>
@code {
[Parameter] public string CurrentName { get; set; } = string.Empty;
[Parameter] public string DialogTitle { get; set; } = "Kontoname bearbeiten";
[Parameter] public string NameLabel { get; set; } = "Kontoname";
[Parameter] public EventCallback<string> OnSave { get; set; }
[Parameter] public EventCallback OnCancel { get; set; }
private string name = string.Empty;
protected override void OnParametersSet() => name = CurrentName;
private async Task Save()
{
if (!string.IsNullOrWhiteSpace(name))
await OnSave.InvokeAsync(name.Trim());
}
private async Task Cancel() => await OnCancel.InvokeAsync();
}

View File

@@ -0,0 +1,51 @@
using Microsoft.AspNetCore.Components;
namespace Duempelkas.App.Components.Dialogs;
public partial class EditNameDialog
{
#region Parameters
[Parameter]
public string CurrentName { get; set; } = string.Empty;
[Parameter]
public string DialogTitle { get; set; } = "Kontoname bearbeiten";
[Parameter]
public string NameLabel { get; set; } = "Kontoname";
[Parameter]
public EventCallback<string> OnSave { get; set; }
[Parameter]
public EventCallback OnCancel { get; set; }
#endregion
#region Fields
private string name = string.Empty;
#endregion
#region Lifecycle
protected override void OnParametersSet() => name = CurrentName;
#endregion
#region Actions
private async Task Save()
{
if (!string.IsNullOrWhiteSpace(name))
{
await OnSave.InvokeAsync(name.Trim());
}
}
private async Task Cancel() => await OnCancel.InvokeAsync();
#endregion
}

View File

@@ -1,5 +1,4 @@
@inherits LayoutComponentBase @inherits LayoutComponentBase
@using System.Reflection
<div class="d-flex flex-column vh-100"> <div class="d-flex flex-column vh-100">
<nav class="app-navbar d-flex justify-content-between align-items-center"> <nav class="app-navbar d-flex justify-content-between align-items-center">
@@ -33,28 +32,3 @@
</div> </div>
} }
@code {
private bool showAboutDialog;
private void OpenAboutDialog() => showAboutDialog = true;
private void CloseAboutDialog() => showAboutDialog = false;
private static string AppVersion
{
get
{
var entryAssembly = Assembly.GetEntryAssembly();
var infoVersion = entryAssembly?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;
if (!string.IsNullOrWhiteSpace(infoVersion))
{
return infoVersion.Split('+')[0];
}
return entryAssembly?.GetName().Version?.ToString(2) ?? "1.0";
}
}
}

View File

@@ -0,0 +1,42 @@
using System.Reflection;
namespace Duempelkas.App.Components.Layout;
public partial class MainLayout
{
#region Fields
private bool showAboutDialog;
#endregion
#region Properties
private static string AppVersion
{
get
{
var entryAssembly = Assembly.GetEntryAssembly();
var infoVersion = entryAssembly?
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;
if (!string.IsNullOrWhiteSpace(infoVersion))
{
return infoVersion.Split('+')[0];
}
return entryAssembly?.GetName().Version?.ToString(2) ?? "1.0";
}
}
#endregion
#region Event Handlers
private void OpenAboutDialog() => showAboutDialog = true;
private void CloseAboutDialog() => showAboutDialog = false;
#endregion
}

View File

@@ -179,156 +179,3 @@
OnCancel="() => editingTransferEntry = null" /> OnCancel="() => editingTransferEntry = null" />
} }
@code {
[Parameter] public int AccountId { get; set; }
private AccountSummaryDto? account;
private AccountBalanceDto? balance;
private List<EntryDto>? entries;
private bool showAddEntry, showAddTransfer;
private bool showEditName, 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;
private void NavigateBack() => Navigation.NavigateTo("/");
protected override async Task OnParametersSetAsync()
{
await LoadAll();
}
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);
}
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;
}
private static string FormatAmount(decimal amount) => $"{amount:N2} €";
}

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
}

View File

@@ -5,7 +5,6 @@
@inject IPdfStatementService PdfStatementService @inject IPdfStatementService PdfStatementService
@inject IFileSaveService FileSaveService @inject IFileSaveService FileSaveService
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@using System.Globalization
<div class="container-fluid"> <div class="container-fluid">
@@ -108,112 +107,3 @@
OnCancel="CancelRestoreConfirm" /> OnCancel="CancelRestoreConfirm" />
} }
@code {
private List<AccountSummaryDto>? accounts;
private bool showAddAccount;
private bool showEditClubName;
private bool showRestoreConfirm;
private string clubName = string.Empty;
private string? operationMessage;
private string operationMessageClass = "alert-info";
private string? savedPdfPath;
private string DisplayClubName => string.IsNullOrWhiteSpace(clubName) ? "Mein Verein" : clubName;
private decimal TotalClubBalance => accounts?.Sum(a => a.TotalBalance) ?? 0m;
protected override async Task OnInitializedAsync()
{
await LoadClubName();
await LoadAccounts();
}
private async Task LoadAccounts()
{
accounts = await AccountService.GetAllAccountsAsync();
}
private async Task LoadClubName()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
private async Task HandleAccountCreated(string name)
{
await AccountService.CreateAccountAsync(name);
showAddAccount = false;
await LoadAccounts();
}
private async Task HandleSaveClubName(string newName)
{
await SettingsService.SetClubNameAsync(newName);
showEditClubName = false;
await LoadClubName();
}
private async Task HandleBackupAsync()
{
var message = await BackupService.CreateBackupAsync();
if(message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase)) {
SetOperationMessage(message, false);
}
}
private Task HandleRestoreAsync()
{
showRestoreConfirm = true;
return Task.CompletedTask;
}
private void CancelRestoreConfirm()
{
showRestoreConfirm = false;
}
private async Task HandleConfirmRestore()
{
showRestoreConfirm = false;
var message = await BackupService.RestoreBackupAsync();
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
if (isSuccess)
{
// Reload the Blazor app so all components/services re-query from restored DB.
NavigationManager.NavigateTo("/", forceLoad: true);
} else {
SetOperationMessage(message, isSuccess);
}
}
private async Task HandleDashboardExportAsync()
{
var pdf = await PdfStatementService.GenerateDashboardStatementAsync();
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
}
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")) + " €";
}
}

View File

@@ -0,0 +1,142 @@
using System.Globalization;
using Duempelkas.App.Services.Models;
namespace Duempelkas.App.Pages;
public partial class Dashboard
{
#region Fields
private List<AccountSummaryDto>? accounts;
private bool showAddAccount;
private bool showEditClubName;
private bool showRestoreConfirm;
private string clubName = string.Empty;
private string? operationMessage;
private string operationMessageClass = "alert-info";
private string? savedPdfPath;
#endregion
#region Properties
private string DisplayClubName => string.IsNullOrWhiteSpace(clubName) ? "Mein Verein" : clubName;
private decimal TotalClubBalance => accounts?.Sum(a => a.TotalBalance) ?? 0m;
#endregion
#region Lifecycle
protected override async Task OnInitializedAsync()
{
await LoadClubName();
await LoadAccounts();
}
#endregion
#region Data Loading
private async Task LoadAccounts()
{
accounts = await AccountService.GetAllAccountsAsync();
}
private async Task LoadClubName()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
#endregion
#region Actions
private async Task HandleAccountCreated(string name)
{
await AccountService.CreateAccountAsync(name);
showAddAccount = false;
await LoadAccounts();
}
private async Task HandleSaveClubName(string newName)
{
await SettingsService.SetClubNameAsync(newName);
showEditClubName = false;
await LoadClubName();
}
private async Task HandleBackupAsync()
{
var message = await BackupService.CreateBackupAsync();
if (message.Contains("fehlgeschlagen", StringComparison.OrdinalIgnoreCase))
{
SetOperationMessage(message, false);
}
}
private Task HandleRestoreAsync()
{
showRestoreConfirm = true;
return Task.CompletedTask;
}
private void CancelRestoreConfirm()
{
showRestoreConfirm = false;
}
private async Task HandleConfirmRestore()
{
showRestoreConfirm = false;
var message = await BackupService.RestoreBackupAsync();
var isSuccess = message.StartsWith("Wiederherstellung erfolgreich", StringComparison.OrdinalIgnoreCase);
if (isSuccess)
{
NavigationManager.NavigateTo("/", forceLoad: true);
}
else
{
SetOperationMessage(message, isSuccess);
}
}
private async Task HandleDashboardExportAsync()
{
var pdf = await PdfStatementService.GenerateDashboardStatementAsync();
savedPdfPath = await FileSaveService.SaveFileAsync(pdf, $"{DisplayClubName}_Übersicht.pdf");
}
private async Task HandleOpenSavedPdf()
{
if (!string.IsNullOrWhiteSpace(savedPdfPath))
{
await FileSaveService.OpenFileAsync(savedPdfPath);
}
savedPdfPath = null;
}
private void CancelOpenSavedPdf()
{
savedPdfPath = null;
}
#endregion
#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")) + " €";
}
#endregion
}

View File

@@ -29,22 +29,3 @@
</div> </div>
</div> </div>
@code {
private string clubName = string.Empty;
private bool saving;
private bool saved;
protected override async Task OnInitializedAsync()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
private async Task Save()
{
saving = true;
saved = false;
await SettingsService.SetClubNameAsync(clubName);
saved = true;
saving = false;
}
}

View File

@@ -0,0 +1,34 @@
namespace Duempelkas.App.Pages;
public partial class Settings
{
#region Fields
private string clubName = string.Empty;
private bool saving;
private bool saved;
#endregion
#region Lifecycle
protected override async Task OnInitializedAsync()
{
clubName = await SettingsService.GetClubNameAsync() ?? string.Empty;
}
#endregion
#region Actions
private async Task Save()
{
saving = true;
saved = false;
await SettingsService.SetClubNameAsync(clubName);
saved = true;
saving = false;
}
#endregion
}