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 BookingTexts : ComponentBase { [Inject] private IBookingTextRepository bookingTextRepository { get; set; } = null!; [Inject] private IDialogService dialogService { get; set; } = null!; [Inject] private IToastService toastService { get; set; } = null!; private IReadOnlyList source = []; private string filter = ""; private IQueryable Filtered => string.IsNullOrWhiteSpace(filter) ? source.AsQueryable() : source.AsQueryable().Where(t => t.Text.Contains(filter, StringComparison.OrdinalIgnoreCase)); protected override async Task OnInitializedAsync() { source = await bookingTextRepository.GetBookingTextListAsync(); await base.OnInitializedAsync(); } private async Task AddAsync() { var data = new BookingText(); var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { Height = "500px", Title = "Add Buchungstext", PreventDismissOnOverlayClick = true, PreventScroll = true, }); var result = await dialog.Result; if (!result.Cancelled && result.Data != null) { source = await bookingTextRepository.GetBookingTextListAsync(); toastService.ShowToast(ToastIntent.Success, "Buchungstext gespeichert", 3000); } } private async Task EditAsync(string id) { var data = await bookingTextRepository.GetBookingTextAsync(id); var dialog = await dialogService.ShowDialogAsync(data, new DialogParameters() { Height = "500px", Title = "Edit Buchungstext", PreventDismissOnOverlayClick = true, PreventScroll = true, }); var result = await dialog.Result; if (!result.Cancelled && result.Data != null) { source = await bookingTextRepository.GetBookingTextListAsync(); toastService.ShowToast(ToastIntent.Success, "Buchungstext gespeichert", 3000); } } private async Task DeleteAsync(string id) { var bookingText = await bookingTextRepository.GetBookingTextAsync(id); var dialog = await dialogService.ShowConfirmationAsync($"Buchungstext '{bookingText.Text}' wirklich löschen?", "Ja", "Nein", "Buchungstext löschen"); var result = await dialog.Result; if (!result.Cancelled) { await bookingTextRepository.DeleteBookingTextAsync(id); source = await bookingTextRepository.GetBookingTextListAsync(); toastService.ShowToast(ToastIntent.Success, "Buchungstext gelöscht", 3000); } } }