예제 #1
0
        public IActionResult CreateVisa(VisaViewModel vm)
        {
            AdminService service = new AdminService(_context, _userManager, _getterUtils);
            VisaCommand  cmd     = new VisaCommand()
            {
                Nombre       = vm.Nombre,
                paisesNames  = vm.paisesNames,
                regionesName = vm.regionesName
            };

            service.RegisterVisa(cmd, out var errors);

            return(RedirectToAction("Welcome", "User"));
        }
예제 #2
0
        public long RegisterVisa(VisaCommand cmd, out IImmutableList <ValidationResult> errors)
        {
            if (cmd.regionesName != null)
            {
                var aux = new List <Region>();
                foreach (var name in cmd.regionesName)
                {
                    foreach (var region in _regionDbAccess.GetAll())
                    {
                        if (region.Nombre == name)
                        {
                            aux.Add(region);
                        }
                    }
                }

                cmd.Regiones      = aux;
                cmd.RegionesVisas = BuildListOfRegion_Visa(cmd.Regiones, new List <Visa>()
                {
                    new Visa()
                    {
                        Name = cmd.Nombre
                    }
                });
            }

            if (cmd.paisesNames != null)
            {
                var aux = new List <Pais>();
                foreach (var name in cmd.paisesNames)
                {
                    foreach (var pais in _paisDbAccess.GetAll())
                    {
                        if (pais.Nombre == name)
                        {
                            aux.Add(pais);
                        }
                    }
                }

                cmd.Paises      = aux;
                cmd.PaisesVisas = BuildListOfPais_Visa(cmd.Paises, new List <Visa>()
                {
                    new Visa()
                    {
                        Name = cmd.Nombre
                    }
                });
            }

            var visa = _runnerVisa.RunAction(cmd);

            if (_runnerVisa.HasErrors)
            {
                errors = _runnerVisa.Errors;
                return(-1);
            }

            errors = null;
            return(visa.VisaID);
        }