public IHttpActionResult PutExcercise(int id, Excercise excercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != excercise.Id) { return BadRequest(); } _ctx.Entry(excercise).State = EntityState.Modified; try { _ctx.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ExcerciseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostExcercise(Excercise newExcercise) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _ctx.Excercises.Add(newExcercise); _ctx.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = newExcercise.Id }, newExcercise); }