public IHttpActionResult PutContraction(int id, Contraction contraction) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != contraction.Id || !CurrentUser.Contractions.Any(c => c.Id == id)) { return BadRequest(); } db.Entry(contraction).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContractionExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostContraction(Contraction contraction) { if (!ModelState.IsValid) { return BadRequest(ModelState); } CurrentUser.Contractions.Add(contraction); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = contraction.Id }, contraction); }