@page "/suppliers"
@inject SupplierService SupplierService
@inject NavigationManager Navigation
Suppliers
@if (loading)
{
Loading...
}
else if (suppliers.Count == 0)
{
}
else
{
| Name |
Contact Info |
Notes |
Actions |
@foreach (var supplier in suppliers)
{
| @supplier.Name |
@supplier.ContactInfo |
@TruncateText(supplier.Notes, 50) |
Edit
|
}
}
@code {
private List suppliers = new();
private bool loading = true;
private ConfirmDialog deleteDialog = null!;
private Supplier? supplierToDelete;
private string deleteMessage = "";
protected override async Task OnInitializedAsync()
{
suppliers = await SupplierService.GetAllAsync();
loading = false;
}
private void ConfirmDelete(Supplier supplier)
{
supplierToDelete = supplier;
deleteMessage = $"Are you sure you want to delete \"{supplier.Name}\"? This will also remove all stock lengths associated with this supplier.";
deleteDialog.Show();
}
private async Task DeleteConfirmed()
{
if (supplierToDelete != null)
{
await SupplierService.DeleteAsync(supplierToDelete.Id);
suppliers = await SupplierService.GetAllAsync();
}
}
private string? TruncateText(string? text, int maxLength)
{
if (string.IsNullOrEmpty(text) || text.Length <= maxLength)
return text;
return text.Substring(0, maxLength) + "...";
}
}