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