Skip to content

Commit

Permalink
Merge pull request #50 from stdevRulo/m.tenorio
Browse files Browse the repository at this point in the history
UpdateVisa tested and ok.
  • Loading branch information
juandamdc authored May 24, 2019
2 parents d68263e + 1f5e305 commit 8dd195c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions TripManager2.0/Controllers/EditorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,41 +217,52 @@ public IActionResult UpdateVisa(EditVisaViewModel vm)
Name = vm.Nombre
};

if (vm.SelectedRegion != null || vm.SelectedRegion.Count() > 0)
if (vm.SelectedRegion != null && vm.SelectedRegion.Count() > 0)
{
var regiones = (IEnumerable<Region>)getter.GetAll("Region");
var regiones_visas = (IEnumerable<Region_Visa>)getter.GetAll("Region_Visa");
List<Region_Visa> regiones_visa = new List<Region_Visa>();

foreach (var name in vm.SelectedRegion)
foreach (var region in regiones)
{
if (region.Nombre == name)
{
regiones_visa.Add(new Region_Visa() { Region = region, Visa = toUpd });
var old = regiones_visas.Where(rv => rv.Region.Nombre == name && rv.Visa.Name == toUpd.Name).SingleOrDefault();
if (old != null)
regiones_visa.Add(old);
else
regiones_visa.Add(new Region_Visa() { Region = region, Visa = toUpd });
break;
}
}
toUpd.Regiones = regiones_visa;
}

if (vm.SelectedPais != null || vm.SelectedPais.Count() > 0)
if (vm.SelectedPais != null && vm.SelectedPais.Count() > 0)
{
var paises = (IEnumerable<Pais>)getter.GetAll("Pais");
var paises_visas = (IEnumerable<Pais_Visa>)getter.GetAll("Pais_Visa");
List<Pais_Visa> paises_visa = new List<Pais_Visa>();

foreach (var name in vm.SelectedPais)
foreach (var pais in paises)
{
if (pais.Nombre == name)
{
paises_visa.Add(new Pais_Visa() { Pais = pais, Visa = toUpd });
var old = paises_visas.Where(pv => pv.Pais.Nombre == name && pv.Visa.Name == toUpd.Name).SingleOrDefault();
if (old != null)
paises_visa.Add(old);
else
paises_visa.Add(new Pais_Visa() { Pais = pais, Visa = toUpd });
break;
}
}
toUpd.Paises = paises_visa;
}

service.UpdateVisa(entity, toUpd);
return RedirectToAction("Welcome");
return RedirectToAction("EditVisa");
}
}
}

0 comments on commit 8dd195c

Please sign in to comment.