All checks were successful
CI/CD Pipeline / Build and Deploy with Docker Compose (push) Successful in 16m35s
87 lines
3.1 KiB
Plaintext
87 lines
3.1 KiB
Plaintext
@page "/stock/productdivisionform/"
|
|
@page "/stock/productdivisionform/{Id:int?}"
|
|
@using phronCare.UIBlazor.Services.Stock
|
|
@using Domain.Entities
|
|
@inject ProductDivisionService productDivisionService
|
|
@inject NavigationManager Navigation
|
|
@inject IToastService toastService
|
|
|
|
<EditForm Model="model" OnValidSubmit="HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
|
|
<div class="card mt-4" style="zoom:80%">
|
|
<div class="card-header d-flex justify-content-center align-items-center">
|
|
<h3 class="card-title m-0">@((model.Id == 0) ? "Nueva División" : "Editar División")</h3>
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-2 mb-3">
|
|
<label for="Code" class="form-label">Código</label>
|
|
<InputText id="Code" class="form-control" @bind-Value="model.Code" />
|
|
<ValidationMessage For="@(() => model.Code)" />
|
|
</div>
|
|
|
|
<div class="col-md-4 mb-3">
|
|
<label for="Name" class="form-label">Nombre</label>
|
|
<InputText id="Name" class="form-control" @bind-Value="model.Name" />
|
|
<ValidationMessage For="@(() => model.Name)" />
|
|
</div>
|
|
|
|
<div class="col-md-6 mb-3">
|
|
<label for="Description" class="form-label">Descripción</label>
|
|
<InputText id="Description" class="form-control" @bind-Value="model.Description" />
|
|
<ValidationMessage For="@(() => model.Description)" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card-footer">
|
|
<div class="d-flex justify-content-end align-items-center py-3">
|
|
<button type="submit" class="btn btn-primary me-2">Guardar</button>
|
|
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancelar</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</EditForm>
|
|
|
|
@code {
|
|
[Parameter]
|
|
public int? Id { get; set; }
|
|
|
|
private ELSProductDivision model = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if (Id.HasValue && Id > 0)
|
|
{
|
|
var result = await productDivisionService.GetByIdAsync(Id.Value);
|
|
if (result != null)
|
|
model = result;
|
|
else
|
|
toastService.ShowError("No se pudo cargar la división de productos.");
|
|
}
|
|
}
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
var response = model.Id == 0
|
|
? await productDivisionService.CreateAsync(model)
|
|
: await productDivisionService.UpdateAsync(model);
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
toastService.ShowSuccess("División guardada correctamente.");
|
|
Navigation.NavigateTo("/stock/productdivisions");
|
|
}
|
|
else
|
|
{
|
|
var error = await response.Content.ReadAsStringAsync();
|
|
toastService.ShowError($"Error: {error}");
|
|
}
|
|
}
|
|
|
|
private void Cancel() => Navigation.NavigateTo("/stock/productdivisions");
|
|
}
|