Ejemplo n.º 1
0
        public ActionResult Crear(Pokemon pokemon, HttpPostedFileBase file)
        {
            List <string> tipos = new List <string>();

            tipos.Add("Agua");
            tipos.Add("Fuego");
            tipos.Add("Planta");
            tipos.Add("Electrico");
            tipos.Add("Roca");
            tipos.Add("Volador");
            tipos.Add("Hielo");
            tipos.Add("Tierra");
            tipos.Add("Acero");
            tipos.Add("Fantasma");

            ViewBag.tipos = tipos;


            if (file != null && file.ContentLength > 0)
            {
                string ruta = Path.Combine(Microsoft.AspNetCore.Server.MapPath("~/imagenes"), Path.GetFileName(file.FileName));
                file.SaveAs(ruta);
                pokemon.Imagen = "/imagenes/" + Path.GetFileName(file.FileName);
            }
            Validar(pokemon);
            if (ModelState.IsValid)
            {
                entidades.Pokemons.Add(pokemon);
                entidades.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(pokemon));
        }