예제 #1
0
        public IHttpActionResult PutWeatherModel(int id, RawWeatherData weatherData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != weatherData.No)
            {
                return(BadRequest());
            }

            db.Entry(weatherData).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeatherModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public IHttpActionResult PostWeatherModel(RawWeatherData weatherData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var weatherModel = new WeatherModel(weatherData);

            db.WeatherModels.Add(weatherModel);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = weatherModel.WeatherModelId }, weatherModel));
        }