BlazorApp/BlazorApp.Client/Pages/Customer/Edit.razor

95 lines
2.8 KiB
Plaintext

@page "/customers/edit/{id}"
@rendermode InteractiveAuto
@attribute [StreamRendering]
@using BlazorApp.Client.Interfaces
@using BlazorApp.Shared.Models
@using BlazorApp.Shared.Queries
@using BlazorApp.Client.Proxies
@using BlazorBootstrap
@inject ToastService ToastService
@inject ICustomerProxy CustomerProxy
@inject NavigationManager NavigationManager
<PageTitle>Επεξεργασία πελάτη</PageTitle>
<h1>Επεξεργασία πελάτη</h1>
<p>Στοιχεία πελάτη</p>
@if (model == null)
{
<p><em>Loading...</em></p>
}
else
{
<EditForm Model="@model" OnValidSubmit="HandleValidSubmit" FormName="EditCustomer">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="mb-3">
<label>CompanyName:</label>
<InputText @bind-Value="model.CompanyName" class="form-control" />
</div>
<div class="mb-3">
<label>ContactName:</label>
<InputText @bind-Value="model.ContactName" class="form-control" />
</div>
<div class="mb-3">
<label>Address:</label>
<InputText @bind-Value="model.Address" class="form-control" />
</div>
<div class="mb-3">
<label>City:</label>
<InputText @bind-Value="model.City" class="form-control" />
</div>
<div class="mb-3">
<label>Region:</label>
<InputText @bind-Value="model.Region" class="form-control" />
</div>
<div class="mb-3">
<label>PostalCode:</label>
<InputText @bind-Value="model.PostalCode" class="form-control" />
</div>
<div class="mb-3">
<label>Country:</label>
<InputText @bind-Value="model.Country" class="form-control" />
</div>
<div class="mb-3">
<label>Phone:</label>
<InputText @bind-Value="model.Phone" class="form-control" />
</div>
<button type="button" @onclick="Back" class="btn btn-light">Πίσω</button>
<button type="submit" class="btn btn-primary">Αποθήκευση</button>
</EditForm>
}
@code {
[Parameter]
public string id { get; set; }
[SupplyParameterFromForm]
private Customer? model { get; set; }
private void Back() => NavigationManager.NavigateTo("customers");
protected override async Task OnInitializedAsync()
{
model = await CustomerProxy.Get(id);
}
private async Task HandleValidSubmit()
{
var success = await CustomerProxy.Update(model);
if (success)
{
ToastService.Notify(new(ToastType.Success, $"Επιτυχής ενημέρωση."));
NavigationManager.NavigateTo("customers");
}
else
{
ToastService.Notify(new(ToastType.Danger, $"Αποτυχία ενημέρωσης."));
}
}
}