public DtoJour(Jour jour) { Id = jour.Id; JourDuVoyage = jour.JourDuVoyage; Budget = jour.Budget; Transports = new List<DtoTransport>(); if (jour.Transports == null) { jour.Transports = new List<Transport>(); } Transports = new List<DtoTransport>(); if (jour.Transports != null) { foreach (Transport transport in jour.Transports) { Transports.Add(new DtoTransport(transport)); } } if (jour.Activites == null) { jour.Activites = new List<Activite>(); } Activites = new List<DtoActivite>(); if (jour.Activites != null) { foreach (Activite activite in jour.Activites) { Activites.Add(new DtoActivite(activite)); } } }
public IHttpActionResult PutJour(int jourid, DtoUpdateJour dtoUpdateJour) { Jour jour = new Jour(); jour = db.Jours.Where(u => u.Id.Equals(jourid)).FirstOrDefault(); jour.Budget = dtoUpdateJour.Budget; if (!ModelState.IsValid) { return BadRequest(ModelState); } if (jourid != jour.Id) { return BadRequest(); } db.Entry(jour).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!JourExists(jourid)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }