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!; private IReadOnlyList accounts = []; private IQueryable? 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(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(); } } private async Task EditAsync(string id) { var data = await transactionRepository.GetTransactionAsync(id); var dialog = await dialogService.ShowDialogAsync(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(); } } 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(); } } }