public IHttpActionResult PostTransport(Transport transport) { transport.Jour = db.Jours.FirstOrDefault(j => j.Id == transport.Jour.Id); if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Jours.FirstOrDefault(j => j.Id == transport.Jour.Id).Transports.Add(transport); db.Entry(db.Jours.FirstOrDefault(j => j.Id == transport.Jour.Id)).State = EntityState.Modified; db.Transports.Add(transport); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = transport.Id }, transport); }
// PUT api/Transports/5 public IHttpActionResult PutTransport(int id, Transport transport) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != transport.Id) { return BadRequest(); } db.Entry(transport).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TransportExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }