AccountingNext/Schaad.Accounting.UI/Components/Pages/Transactions.razor.cs
Claudio Schaad 766295a119 PR U-8: format the Transactions delete-confirmation amount
Route transaction.Value through ToFormattedString() so the confirmation
reads "Betrag 1'234.57" instead of "Betrag 1234.567", and fix the
"Transaction" → "Transaktion" typo. One-file change — the other four
CRUD pages don't put values into confirmations.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-04 10:06:44 +02:00

111 lines
3.9 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;
using Schaad.Accounting.Datasets;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
using Schaad.Accounting.UI.Components.Pages.Dialogs;
namespace Schaad.Accounting.UI.Components.Pages;
public partial class Transactions : ComponentBase
{
[Inject]
private IViewService viewService { get; set; } = null!;
[Inject]
private ITransactionRepository transactionRepository { get; set; } = null!;
[Inject]
private IDialogService dialogService { get; set; } = null!;
[Inject]
private IToastService toastService { get; set; } = null!;
private IReadOnlyList<AccountDataset> accounts = [];
private IQueryable<TransactionDataset>? transactionList;
private string? selectedAccountId;
private AccountDataset? selectedAccount;
protected override async Task OnInitializedAsync()
{
accounts = await viewService.GetAccountViewListAsync();
await ShowTransactionsAsync(accounts.First().Id);
await base.OnInitializedAsync();
}
private async Task ShowTransactionsAsync(string accountId)
{
selectedAccountId = accountId;
selectedAccount = accounts.Single(a => a.Id == accountId);
transactionList = (await viewService.GetTransactionViewListAsync(accountId)).AsQueryable();
}
private string GetAccountName(TransactionDataset transaction)
{
if (selectedAccountId == transaction.OriginAccountId)
{
return transaction.TargetAccount.Name;
}
return transaction.OriginAccount.Name;
}
private async Task AddAsync()
{
var data = new Transaction
{
ValueDate = DateTime.Now,
BookingDate = DateTime.Now,
TargetAccountId = selectedAccountId,
FxRate = 1
};
var dialog = await dialogService.ShowDialogAsync<TransactionDialog>(data, new DialogParameters()
{
Height = "500px",
Title = "Transaktion",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
var result = await dialog.Result;
if (!result.Cancelled && result.Data != null)
{
transactionList = (await viewService.GetTransactionViewListAsync(selectedAccountId)).AsQueryable();
toastService.ShowToast(ToastIntent.Success, "Transaktion gespeichert", 3000);
}
}
private async Task EditAsync(string id)
{
var data = await transactionRepository.GetTransactionAsync(id);
var dialog = await dialogService.ShowDialogAsync<TransactionDialog>(data, new DialogParameters()
{
Height = "500px",
Title = "Transaktion",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
var result = await dialog.Result;
if (!result.Cancelled && result.Data != null)
{
transactionList = (await viewService.GetTransactionViewListAsync(selectedAccountId)).AsQueryable();
toastService.ShowToast(ToastIntent.Success, "Transaktion gespeichert", 3000);
}
}
private async Task DeleteAsync(string id)
{
var transaction = await transactionRepository.GetTransactionAsync(id);
var message = $"Transaktion '{transaction.Text}' mit Betrag {transaction.Value.ToFormattedString()} wirklich löschen?";
var dialog = await dialogService.ShowConfirmationAsync(message, "Ja", "Nein", "Transaktion löschen");
var result = await dialog.Result;
if (!result.Cancelled)
{
await transactionRepository.DeleteTransactionAsync(id);
transactionList = (await viewService.GetTransactionViewListAsync(selectedAccountId)).AsQueryable();
toastService.ShowToast(ToastIntent.Success, "Transaktion gelöscht", 3000);
}
}
}