public async Task<IHttpActionResult> PutTeacher(int id, Teacher teacher) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != teacher.Id) { return BadRequest(); } db.Entry(teacher).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeacherExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostTeacher(Teacher teacher) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Teachers.Add(teacher); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = teacher.Id }, teacher); }