예제 #1
0
        // PUT odata/Weather(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, Weather weather)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (key != weather.WeatherId)
            {
                return BadRequest();
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WeatherExists(key))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return Updated(weather);
        }
예제 #2
0
        // POST odata/Weather
        public async Task<IHttpActionResult> Post(Weather weather)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Weathers.Add(weather);
            await db.SaveChangesAsync();

            return Created(weather);
        }