Accounts, BookingRules, BookingTexts, BankTransactions each get an <FluentSearch> above the grid, backed by a computed Filtered IQueryable over an in-memory source list. FluentSearch is Immediate, so filtering happens on each keystroke; data sizes are small enough for per-render LINQ. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
87 lines
3 KiB
C#
87 lines
3 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.FluentUI.AspNetCore.Components;
|
|
using Schaad.Accounting.Interfaces;
|
|
using Schaad.Accounting.Models;
|
|
using Schaad.Accounting.UI.Components.Pages.Dialogs;
|
|
|
|
namespace Schaad.Accounting.UI.Components.Pages;
|
|
|
|
public partial class Accounts : ComponentBase
|
|
{
|
|
[Inject]
|
|
private IAccountRepository accountRepository { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IDialogService dialogService { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IToastService toastService { get; set; } = null!;
|
|
|
|
private IReadOnlyList<Account> source = [];
|
|
private string filter = "";
|
|
|
|
private IQueryable<Account> Filtered =>
|
|
string.IsNullOrWhiteSpace(filter)
|
|
? source.AsQueryable()
|
|
: source.AsQueryable().Where(a =>
|
|
a.Name.Contains(filter, StringComparison.OrdinalIgnoreCase) ||
|
|
a.Number.ToString().Contains(filter) ||
|
|
(a.BankAccountNumber != null && a.BankAccountNumber.Contains(filter, StringComparison.OrdinalIgnoreCase)));
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
source = await accountRepository.GetAccountListAsync();
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private async Task AddAsync()
|
|
{
|
|
var data = new Account();
|
|
var dialog = await dialogService.ShowDialogAsync<AccountDialog>(data, new DialogParameters()
|
|
{
|
|
Height = "500px",
|
|
Title = "Konto",
|
|
PreventDismissOnOverlayClick = true,
|
|
PreventScroll = true,
|
|
});
|
|
|
|
var result = await dialog.Result;
|
|
if (!result.Cancelled && result.Data != null)
|
|
{
|
|
source = await accountRepository.GetAccountListAsync();
|
|
toastService.ShowToast(ToastIntent.Success, "Konto gespeichert", 3000);
|
|
}
|
|
}
|
|
|
|
private async Task EditAsync(string id)
|
|
{
|
|
var data = await accountRepository.GetAccountAsync(id);
|
|
var dialog = await dialogService.ShowDialogAsync<AccountDialog>(data, new DialogParameters()
|
|
{
|
|
Height = "500px",
|
|
Title = "Konto",
|
|
PreventDismissOnOverlayClick = true,
|
|
PreventScroll = true,
|
|
});
|
|
|
|
var result = await dialog.Result;
|
|
if (!result.Cancelled && result.Data != null)
|
|
{
|
|
source = await accountRepository.GetAccountListAsync();
|
|
toastService.ShowToast(ToastIntent.Success, "Konto gespeichert", 3000);
|
|
}
|
|
}
|
|
|
|
private async Task DeleteAsync(string id)
|
|
{
|
|
var account = await accountRepository.GetAccountAsync(id);
|
|
var dialog = await dialogService.ShowConfirmationAsync($"Konto '{account.Name}' wirklich löschen?", "Ja", "Nein", "Konto löschen");
|
|
var result = await dialog.Result;
|
|
if (!result.Cancelled)
|
|
{
|
|
await accountRepository.DeleteAccountAsync(id);
|
|
source = await accountRepository.GetAccountListAsync();
|
|
toastService.ShowToast(ToastIntent.Success, "Konto gelöscht", 3000);
|
|
}
|
|
}
|
|
}
|