public IHttpActionResult PostTransport(DtoCreateTransport dtoCreateTransport) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Transport transport = new Transport(); transport.AdresseArrive = dtoCreateTransport.AdresseArrive; transport.AdresseDepart = dtoCreateTransport.AdresseDepart; transport.Budget = dtoCreateTransport.Budget; transport.NomTransporteur = dtoCreateTransport.NomTransporteur; transport.TypeTransport = dtoCreateTransport.TypeTransport; Jour jourDuTransport = db.Jours.Where(u => u.Id.Equals(dtoCreateTransport.JourId)).FirstOrDefault(); if(jourDuTransport == null) { return BadRequest(); } transport.Jour = jourDuTransport; db.Transports.Add(transport); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = transport.Id }, new DtoTransport(transport)); }
public DtoTransport(Transport transport) { Id = transport.Id; NomTransporteur = transport.NomTransporteur; TypeTransport = transport.TypeTransport; Budget = transport.Budget; AdresseDepart = transport.AdresseDepart; AdresseArrive = transport.AdresseArrive; }