public IHttpActionResult PostCity(City city) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Cities.Add(city); try { db.SaveChanges(); } catch (DbUpdateException) { if (CityExists(city.CityId_PK)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = city.CityId_PK }, city); }
// PUT api/CityAPI/5 public IHttpActionResult PutCity(Guid id, City city) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != city.CityId_PK) { return BadRequest(); } db.Entry(city).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CityExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }