- @if (address.Country == "Argentina")
- {
-
- }
- else
- {
-
- }
-
+
+
-
-
-
+
+
-}
-
+
+
+
+
+
+
+
+ @if (editingAddress.Country == "Argentina" && provincesByCountry.TryGetValue("Argentina", out var provincias))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+ @if (editingIndex != -1)
+ {
+
+ }
+
+
+ @if (customer.PhSCustomerAddresses.Any())
+ {
+
+
+
+ | Sucursal |
+ Dirección |
+ Ciudad |
+ Provincia |
+ País |
+ |
+
+
+
+ @foreach (var address in customer.PhSCustomerAddresses.Select((value, index) => new { value, index }))
+ {
+
+ | @address.value.BusinessName |
+ @address.value.Streetaddress1 |
+ @address.value.City |
+ @address.value.Stateprovince |
+ @address.value.Country |
+
+
+
+ |
+
+ }
+
+
+ }
@code {
@@ -191,11 +229,110 @@
private List
taxConditions = new();
private List documentTypes = new();
private ECustomerDocument documentFormModel = new();
- private ECustomerAddress AddressForModel = new();
- private List addresses => customer.PhSCustomerAddresses.ToList();
private string returnUrl = "/sales/customers";
+ private List countries = new() {
+ "Argentina", "Brasil", "Chile", "Uruguay", "Paraguay", "Estados Unidos", "Canadá",
+ "México", "Alemania", "Reino Unido", "Francia", "Italia", "España"
+ };
+
+ private Dictionary> provincesByCountry = new()
+ {
+ {
+ "Argentina", new List
+ {
+ "Buenos Aires", "CABA", "Catamarca", "Chaco", "Chubut", "Córdoba", "Corrientes",
+ "Entre Ríos", "Formosa", "Jujuy", "La Pampa", "La Rioja", "Mendoza", "Misiones",
+ "Neuquén", "Río Negro", "Salta", "San Juan", "San Luis", "Santa Cruz",
+ "Santa Fe", "Santiago del Estero", "Tierra del Fuego", "Tucumán"
+ }
+ }
+ };
+
+ private ECustomerAddress editingAddress = new();
+ private int editingIndex = -1;
+
+ private void OnCountryChanged(ChangeEventArgs e)
+ {
+ var selectedCountry = e.Value?.ToString();
+ editingAddress.Country = selectedCountry;
+ editingAddress.Stateprovince = string.Empty; // Resetear la provincia si cambia el país
+ }
+
+ private void AddOrUpdateAddress()
+ {
+ if (editingIndex == -1)
+ {
+ // Agregar nueva dirección
+ customer.PhSCustomerAddresses.Add(editingAddress);
+ }
+ else
+ {
+ // Actualizar dirección existente
+ var existing = customer.PhSCustomerAddresses.ElementAt(editingIndex);
+
+ existing.BusinessName = editingAddress.BusinessName;
+ existing.Streetaddress1 = editingAddress.Streetaddress1;
+ existing.Streetaddress2 = editingAddress.Streetaddress2;
+ existing.City = editingAddress.City;
+ existing.Stateprovince = editingAddress.Stateprovince;
+ existing.Postalcode = editingAddress.Postalcode;
+ existing.Country = editingAddress.Country;
+ existing.Latitude = editingAddress.Latitude;
+ existing.Longitude = editingAddress.Longitude;
+ existing.Phonenumber = editingAddress.Phonenumber;
+ existing.Email = editingAddress.Email;
+ existing.Notes = editingAddress.Notes;
+ }
+
+ ResetAddressForm();
+ }
+
+ private void EditAddress(int index)
+ {
+ var addr = customer.PhSCustomerAddresses.ElementAt(index);
+
+ editingAddress = new ECustomerAddress
+ {
+ Id = addr.Id, // Incluí el Id como mencionamos antes, para no perder referencia
+ BusinessName = addr.BusinessName,
+ Streetaddress1 = addr.Streetaddress1,
+ Streetaddress2 = addr.Streetaddress2,
+ City = addr.City,
+ Stateprovince = addr.Stateprovince,
+ Postalcode = addr.Postalcode,
+ Country = addr.Country,
+ Latitude = addr.Latitude,
+ Longitude = addr.Longitude,
+ Phonenumber = addr.Phonenumber,
+ Email = addr.Email,
+ Notes = addr.Notes
+ };
+
+ editingIndex = index;
+ }
+
+ private void RemoveAddress(int index)
+ {
+ var itemToRemove = customer.PhSCustomerAddresses.ElementAt(index);
+ customer.PhSCustomerAddresses.Remove(itemToRemove);
+ ResetAddressForm();
+ }
+
+
+ private void CancelAddressEdit()
+ {
+ ResetAddressForm();
+ }
+
+ private void ResetAddressForm()
+ {
+ editingAddress = new();
+ editingIndex = -1;
+ }
+
+
protected override async Task OnInitializedAsync()
{
await LoadAccountTypes();
@@ -236,56 +373,11 @@
customer.PhSCustomerDocuments.Remove(document);
}
- private void AddCustomerAddress()
- {
- if (!string.IsNullOrWhiteSpace(AddressForModel.Streetaddress1))
- {
- customer.PhSCustomerAddresses.Add(AddressForModel);
- AddressForModel = new(); // limpiar el formulario
- }
- }
private void RemoveCustomerAddress(ECustomerAddress address)
{
customer.PhSCustomerAddresses.Remove(address);
}
- private List countries = new()
- {
- "Argentina", "Brasil", "Chile", "Uruguay", "Paraguay", "Bolivia", "Perú", "Colombia", "Venezuela", "México",
- "Estados Unidos", "Canadá", "España", "Reino Unido", "Alemania", "Francia", "Italia", "China", "India", "Japón"
- };
-
- private List argentinaProvinces = new()
- {
- "Buenos Aires", "Catamarca", "Chaco", "Chubut", "Córdoba", "Corrientes", "Entre Ríos", "Formosa", "Jujuy",
- "La Pampa", "La Rioja", "Mendoza", "Misiones", "Neuquén", "Río Negro", "Salta", "San Juan", "San Luis",
- "Santa Cruz", "Santa Fe", "Santiago del Estero", "Tierra del Fuego", "Tucumán", "Ciudad Autónoma de Buenos Aires"
- };
- private void OnCountryChanged(ChangeEventArgs e, ECustomerAddress address)
- {
- address.Country = e.Value?.ToString();
- if (address.Country != "Argentina")
- {
- address.Stateprovince = string.Empty;
- }
- }
- private void AddAddress()
- {
- customer.PhSCustomerAddresses.Add(new());
- }
-
- private void RemoveAddress(ECustomerAddress address)
- {
- customer.PhSCustomerAddresses.Remove(address);
- }
-
- private void OnCountryChanged(ECustomerAddress address)
- {
- if (address.Country != "Argentina")
- {
- address.Stateprovince = string.Empty;
- }
- }
private async Task HandleValidSubmit()
{
try
diff --git a/phronCare.UIBlazor/Pages/_Imports.razor b/phronCare.UIBlazor/Pages/_Imports.razor
new file mode 100644
index 0000000..e69de29