Ejemplo n.º 1
0
        public IHttpActionResult Create(PlanetCreateModel planetToCreate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var planetService = CreatePlanetService();

            planetService.CreatePlanet(planetToCreate);
            return(Ok());
        }
        public void CreatePlanet(PlanetCreateModel planetToCreate)
        {
            var entity = new Planet()
            {
                PlanetName        = planetToCreate.PlanetName,
                PlanetDescription = planetToCreate.PlanetDescription,
                PlanetClimate     = planetToCreate.PlanetClimate,
                HoursPerDay       = planetToCreate.HoursPerDay,
                DaysPerYear       = planetToCreate.DaysPerYear,
                NumberOfSuns      = planetToCreate.NumberOfSuns,
                NumberOfMoons     = planetToCreate.NumberOfMoons
            };

            _ctx.Planets.Add(entity);
            _ctx.SaveChanges();
        }