public IHttpActionResult PutStudent(int id, Student student) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != student.ID) { return BadRequest(); } db.Entry(student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostStudent(Student student) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Students.Add(student); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = student.ID }, student); }