Ejemplo n.º 1
0
        public ActionResult Save(Planet planet)
        {
            if (!ModelState.IsValid)
            {
                var ViewModel = new PlantFormViewModel(planet)
                {
                    PlanetsTypes = _context.PlanetsTypes.ToList()
                };
                return(View("PlanetForm", ViewModel));
            }
            if (planet.Id == 0)
            {
                _context.Planets.Add(planet);
            }

            else
            {
                var planetInDb = _context.Planets.Single(c => c.Id == planet.Id);
                planetInDb.Name          = planet.Name;
                planetInDb.Galaxy        = planet.Galaxy;
                planetInDb.Features      = planet.Features;
                planetInDb.PlanetsTypeId = planet.PlanetsTypeId;
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Planet"));
        }
Ejemplo n.º 2
0
        public ActionResult CreatePlanet()
        {
            var planetType = _context.PlanetsTypes.ToList();
            var ViewModel  = new PlantFormViewModel
            {
                PlanetsTypes = planetType,
            };

            return(View("PlanetForm", ViewModel));
        }
Ejemplo n.º 3
0
        public ActionResult EditPlanet(int id)
        {
            var Planet = _context.Planets.Single(c => c.Id == id);

            if (Planet == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var ViewModel = new PlantFormViewModel(Planet)
                {
                    PlanetsTypes = _context.PlanetsTypes.ToList()
                };
                return(View("PlanetForm", ViewModel));
            }
        }