@page "/customers"
@rendermode InteractiveAuto
@using BlazorApp.Client.Interfaces
@using BlazorApp.Shared.Models
@using BlazorApp.Shared.Models.Pagination
@using BlazorApp.Shared.Queries
@using BlazorApp.Client.Proxies
@inject ToastService ToastService
@inject IHttpClientFactory ClientFactory
@attribute [StreamRendering]
@inject ICustomerProxy CustomerProxy
@inject NavigationManager NavigationManager
@using BlazorBootstrap
Customers
Customers
This component demonstrates showing data.
@if (model == null)
{
Loading...
}
else
{
| Id |
CompanyName |
ContactName |
Address |
City |
Region |
PostalCode |
Country |
Phone |
Actions |
@foreach (var result in model.Results)
{
| @result.Id |
@result.CompanyName |
@result.ContactName |
@result.Address |
@result.City |
@result.Region |
@result.PostalCode |
@result.Country |
@result.Phone |
|
}
}
@code {
private PaginatedResult model;
private int activePageIndex = 0;
private int resultsPerPage = 10;
private int totalPages { get => model.TotalCount % resultsPerPage != 0 ? (model.TotalCount / resultsPerPage) + 1 : (model.TotalCount / resultsPerPage); }
protected override async Task OnInitializedAsync()
{
model = await CustomerProxy.Query(activePageIndex, resultsPerPage);
}
private async Task OnPageChangedAsync(int newPageNumber)
{
activePageIndex = newPageNumber - 1;
model = await CustomerProxy.Query(activePageIndex, resultsPerPage);
}
private void NewCustomer() => NavigationManager.NavigateTo("customers/new");
private void EditCustomer(string id) => NavigationManager.NavigateTo($"customers/edit/{id}");
private async Task DeleteCustomer(string id)
{
var success = await CustomerProxy.Delete(id);
if (success)
{
ToastService.Notify(new(ToastType.Success, $"Επιτυχής διαγραφή."));
model = await CustomerProxy.Query(activePageIndex, resultsPerPage);
}
else
{
ToastService.Notify(new(ToastType.Danger, $"Αποτυχία διαγραφής."));
}
}
}