public IHttpActionResult PostExercise(Exercise exercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Exercises.Add(exercise); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = exercise.Id }, exercise); }
public IHttpActionResult PutExercise(int id, Exercise exercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != exercise.Id) { return BadRequest(); } db.Entry(exercise).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ExerciseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }