113 lines
3.7 KiB
Plaintext
113 lines
3.7 KiB
Plaintext
@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
|
|
|
|
<PageTitle>Customers</PageTitle>
|
|
|
|
<h1>Customers</h1>
|
|
|
|
<p>This component demonstrates showing data.</p>
|
|
|
|
@if (model == null)
|
|
{
|
|
<p><em>Loading...</em></p>
|
|
}
|
|
else
|
|
{
|
|
<table class="table">
|
|
<thead>
|
|
<tr>
|
|
<th>Id</th>
|
|
<th>CompanyName</th>
|
|
<th>ContactName</th>
|
|
<th>Address</th>
|
|
<th>City</th>
|
|
<th>Region</th>
|
|
<th>PostalCode</th>
|
|
<th>Country</th>
|
|
<th>Phone</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@foreach (var result in model.Results)
|
|
{
|
|
<tr>
|
|
<td>@result.Id</td>
|
|
<td>@result.CompanyName</td>
|
|
<td>@result.ContactName</td>
|
|
<td>@result.Address</td>
|
|
<td>@result.City</td>
|
|
<td>@result.Region</td>
|
|
<td>@result.PostalCode</td>
|
|
<td>@result.Country</td>
|
|
<td>@result.Phone</td>
|
|
<td>
|
|
<button type="button" @onclick="() => EditCustomer(result.Id)" class="btn btn-secondary">Επεξεργασια</button>
|
|
<button type="button" @onclick="async () => await DeleteCustomer(result.Id)" class="btn btn-danger">
|
|
Διαγραφή
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
<Pagination ActivePageNumber="activePageIndex + 1"
|
|
TotalPages="totalPages"
|
|
DisplayPages="5"
|
|
Alignment="Alignment.Center"
|
|
FirstLinkIcon="IconName.ChevronDoubleLeft"
|
|
PreviousLinkIcon="IconName.ChevronLeft"
|
|
NextLinkIcon="IconName.ChevronRight"
|
|
LastLinkIcon="IconName.ChevronDoubleRight"
|
|
PageChanged="OnPageChangedAsync" />
|
|
}
|
|
<button type="button" @onclick="NewCustomer" class="btn btn-primary">Προσθήκη πελάτη</button>
|
|
|
|
@code {
|
|
private PaginatedResult<Customer> 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, $"Αποτυχία διαγραφής."));
|
|
}
|
|
}
|
|
}
|