public IHttpActionResult PostCountry(Country country) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Countries.Add(country); try { db.SaveChanges(); } catch (DbUpdateException) { if (CountryExists(country.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = country.Id }, country); }
public IHttpActionResult PutCountry(string id, Country country) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != country.Id) { return BadRequest(); } db.Entry(country).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CountryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }