public async Task<IHttpActionResult> PutExercise(long id, Exercise exercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != exercise.Id) { return BadRequest(); } if (db.Entry(exercise).Entity.Set.AspNetUser.Id.ToLower().CompareTo(user.Id.ToLower()) != 0) return NotFound(); db.Entry(exercise).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExerciseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostExercise(Exercise exercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Exercises.Add(exercise); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = exercise.Id }, exercise); }