@page "/sales/customerform" @page "/sales/customerform/{CustomerId:int}" @using phronCare.UIBlazor.Services.Sales @inject HttpClient _httpClient @inject NavigationManager Navigation @inject IToastService toastService @inject AuthenticationStateProvider authenticationStateProvider @inject AccountTypeService accountTypeService @inject TaxConditionService taxConditionService
@foreach (var type in accountTypes) { }
@foreach (var tax in taxConditions) { }



Documentos
@foreach (var tipo in documentTypes) { }

@if (customer.PhSCustomerDocuments?.Any() == true) { @foreach (var doc in customer.PhSCustomerDocuments) { }
Tipo Número
@documentTypes.FirstOrDefault(t => t.Id == doc.DocumenttypesId)?.Name @doc.DocumentNumber
}
@code { [Parameter] public int? CustomerId { get; set; } private ECustomer customer { get; set; } = new(); private List accountTypes = new(); private List taxConditions = new(); private List documentTypes = new(); private ECustomerDocument documentFormModel = new(); private string returnUrl = "/sales/customers"; protected override async Task OnInitializedAsync() { await LoadAccountTypes(); await LoadTaxConditions(); if (CustomerId.HasValue) { // Cargar datos del cliente existente desde la API customer = await _httpClient.GetFromJsonAsync($"/api/Customer/GetById/{CustomerId.Value}") ?? new(); } } private async Task LoadAccountTypes() { accountTypes = await accountTypeService.GetAllAsync(); } private async Task LoadTaxConditions() { taxConditions = await taxConditionService.GetAllAsync(); } private async Task LoadDocumentTypes() { var result = await _httpClient.GetFromJsonAsync>("/api/DocumentType/GetAll"); documentTypes = result ?? new(); } private void AddCustomerDocument() { if (!string.IsNullOrWhiteSpace(documentFormModel.DocumentNumber)) { customer.PhSCustomerDocuments.Add(documentFormModel); documentFormModel = new(); } } private void RemoveCustomerDocument(ECustomerDocument document) { customer.PhSCustomerDocuments.Remove(document); } private async Task HandleValidSubmit() { try { HttpResponseMessage response; if (CustomerId.HasValue) { response = await _httpClient.PutAsJsonAsync("/api/Customer/Update", customer); } else { response = await _httpClient.PostAsJsonAsync("/api/Customer/Create", customer); } if (response.IsSuccessStatusCode) { toastService.ShowSuccess("Cliente guardado exitosamente"); Navigation.NavigateTo(returnUrl); } else { var error = await response.Content.ReadAsStringAsync(); toastService.ShowError($"Error: {error}"); } } catch (Exception ex) { toastService.ShowError($"Error: {ex.Message}"); } } private void Cancel() { Navigation.NavigateTo(returnUrl); } }