BlazorApp/BlazorApp.Client/Pages/Customer/New.razor

81 lines
2.5 KiB
Plaintext

@page "/customers/new"
@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>
<EditForm Model="@model" OnValidSubmit="HandleValidSubmit" FormName="NewCustomer">
<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 {
[SupplyParameterFromForm]
private Customer? model { get; set; }
protected override void OnInitialized() => model ??= new();
private void Back() => NavigationManager.NavigateTo("customers");
private async Task HandleValidSubmit()
{
var success = await CustomerProxy.Save(model);
if (success)
{
ToastService.Notify(new(ToastType.Success, $"Επιτυχής δημιουργία."));
NavigationManager.NavigateTo("customers");
}
else
{
ToastService.Notify(new(ToastType.Danger, $"Αποτυχία δημιουργίας."));
}
}
}