85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
using BimAI.UI.Shared.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using BimAI.Application.DTOModels;
|
|
using BimAI.Application.DTOModels.Common;
|
|
using MudBlazor;
|
|
|
|
namespace BimAI.UI.Shared.Components;
|
|
|
|
public partial class InvoiceListComponent : ComponentBase
|
|
{
|
|
[Inject] private InvoiceService InvoiceService { get; set; } = default!;
|
|
[Inject] private ISnackbar Snackbar { get; set; } = default!;
|
|
|
|
private PagedResult<InvoiceDto> invoices = new();
|
|
private InvoiceFilterRequest filterRequest = new();
|
|
private bool isLoading = false;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadInvoices();
|
|
}
|
|
|
|
private async Task LoadInvoices()
|
|
{
|
|
isLoading = true;
|
|
|
|
try
|
|
{
|
|
var result = await InvoiceService.GetInvoiceAsync(filterRequest);
|
|
invoices = result ?? new PagedResult<InvoiceDto>();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Loading invoices failed: {ex.Message}");
|
|
Console.WriteLine($"Stack trace: {ex.StackTrace}");
|
|
Snackbar.Add($"Błąd podczas ładowania faktur: {ex.Message}", Severity.Error);
|
|
invoices = new PagedResult<InvoiceDto>();
|
|
}
|
|
finally
|
|
{
|
|
isLoading = false;
|
|
}
|
|
}
|
|
|
|
private async Task SearchInvoices()
|
|
{
|
|
filterRequest.Page = 1;
|
|
await LoadInvoices();
|
|
}
|
|
|
|
private async Task OnPageChanged(int page)
|
|
{
|
|
filterRequest.Page = page;
|
|
await LoadInvoices();
|
|
}
|
|
private async Task OnFilterChanged()
|
|
{
|
|
filterRequest.Page = 1;
|
|
await SearchInvoices();
|
|
}
|
|
|
|
private async Task ClearFilters()
|
|
{
|
|
filterRequest = new InvoiceFilterRequest();
|
|
await LoadInvoices();
|
|
}
|
|
|
|
private async Task ViewInvoice(Guid invoiceId)
|
|
{
|
|
// TODO
|
|
Console.WriteLine($"Zobacz fakturę: {invoiceId}");
|
|
}
|
|
|
|
private async Task EditInvoice(Guid invoiceId)
|
|
{
|
|
// TODO
|
|
Console.WriteLine($"Edytuj fakturę: {invoiceId}");
|
|
}
|
|
|
|
private async Task DeleteInvoice(Guid invoiceId)
|
|
{
|
|
// TODO
|
|
Console.WriteLine($"Usuń fakturę: {invoiceId}");
|
|
}
|
|
} |