Add IToastService.ShowToast(ToastIntent.Success, ...) after each successful save/delete across Accounts, BookingRules, BookingTexts, Classes, and Transactions. Toasts fire after the list re-fetch so the confirmation is visible even if the edited item paginated out of view. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
110 lines
3.8 KiB
C#
110 lines
3.8 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 dialog = await dialogService.ShowConfirmationAsync($"Transaction '{transaction.Text}' mit Betrag {transaction.Value} wirklich löschen?", "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);
|
|
}
|
|
}
|
|
}
|