@page "/sales/personform" @page "/sales/personform/{PersonId:int}" @using System.ComponentModel.DataAnnotations @using phronCare.UIBlazor.Services.Sales @using phronCare.UIBlazor.Shared.Modals @inject BusinessUnitService businessUnitService @inject NavigationManager Navigation @inject PeopleService peopleService @inject IToastService toastService @inject IModalService Modal

Información de la Persona

@foreach (var unit in businessUnits) { }
@foreach (var group in peopleGroups) { }
@code { [Parameter] public int? PersonId { get; set; } private EPerson person { get; set; } = new(); private bool isSaving = false; private string returnUrl = "/sales/people"; private List businessUnits = new(); private List peopleGroups = new(); protected override async Task OnInitializedAsync() { await LoadBusinessUnits(); await LoadPeopleGroups(); if (PersonId.HasValue) { person = await peopleService.GetPersonByIdAsync(PersonId.Value) ?? new(); } } private async Task HandleValidSubmit() { var parameters = new ModalParameters(); parameters.Add("Message", "¿Desea guardar los cambios de la persona?"); var modal = Modal.Show("Confirmación", parameters); var result = await modal.Result; if (result.Cancelled) return; try { isSaving = true; if (PersonId.HasValue) { await peopleService.UpdatePersonAsync(person); } else { await peopleService.CreatePersonAsync(person); } toastService.ShowSuccess("Persona guardada exitosamente."); Navigation.NavigateTo(returnUrl); } catch (Exception ex) { toastService.ShowError($"Error: {ex.Message}"); } finally { isSaving = false; } } private void Cancel() { Navigation.NavigateTo(returnUrl); } private async Task LoadBusinessUnits() { businessUnits = await businessUnitService.GetAllAsync(); } private async Task LoadPeopleGroups() { // Simulamos carga de Grupos Comerciales. Debería venir de un servicio real. peopleGroups = new List { new EPeopleGroup { Id = 1, Name = "Grupo 1" }, new EPeopleGroup { Id = 2, Name = "Grupo 2" }, }; } }