Exemplo n.º 1
0
        public IHttpActionResult Update(PlanetUpdateModel planetToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var planetService = CreatePlanetService();

            planetService.UpdatePlanet(planetToUpdate);
            return(Ok());
        }
Exemplo n.º 2
0
        public IHttpActionResult UpdatePlanet([FromUri] int planetId, PlanetUpdateModel planetToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreatePlanetService();

            service.UpdatePlanetById(planetId, planetToUpdate);
            return(Ok());
        }
Exemplo n.º 3
0
        public void UpdatePlanetById(int planetId, PlanetUpdateModel planetToUpdate)
        {
            var entity = _ctx.Planets.Single(e => e.PlanetId == planetId);

            if (entity != null)
            {
                if (planetToUpdate.UpdatedPlanetName != null)
                {
                    entity.PlanetName = planetToUpdate.UpdatedPlanetName;
                }
                if (planetToUpdate.UpdatedPlanetDescription != null)
                {
                    entity.PlanetDescription = planetToUpdate.UpdatedPlanetDescription;
                }
                if (planetToUpdate.UpdatedPlanetClimate != null)
                {
                    entity.PlanetClimate = planetToUpdate.UpdatedPlanetClimate;
                }
                if (planetToUpdate.UpdatedHoursPerDay != null)
                {
                    entity.HoursPerDay = (int)planetToUpdate.UpdatedHoursPerDay;
                }
                if (planetToUpdate.UpdatedDaysPerYear != null)
                {
                    entity.DaysPerYear = (int)planetToUpdate.UpdatedDaysPerYear;
                }
                if (planetToUpdate.UpdatedNumberOfSuns != null)
                {
                    entity.NumberOfSuns = (int)planetToUpdate.UpdatedNumberOfSuns;
                }
                if (planetToUpdate.UpdatedNumberOfMoons != null)
                {
                    entity.NumberOfMoons = (int)planetToUpdate.UpdatedNumberOfMoons;
                }
                if (planetToUpdate.UpdatedPrice != null)
                {
                    entity.Price = (int)planetToUpdate.UpdatedPrice;
                }
                _ctx.SaveChanges();
            }
        }