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); }
public IHttpActionResult PostExercise(Exercise exercise) { // Add default values exercise.CreationDate = DateTime.Now; exercise.LastUpdatedDate = DateTime.Now; if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Exercises.Add(exercise); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = exercise.Id }, exercise); }