public IHttpActionResult PostSchool(School school) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Schools.Add(school); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = school.Id }, school); }
public IHttpActionResult PutSchool(int id, School school) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != school.Id) { return BadRequest(); } db.Entry(school).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SchoolExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }