public JourDTO(Jour j) { Id = j.Id; BudgetJournee = j.BudgetJournee; Date = j.Date; if (j.Voyage != null) { VoyageId = j.Voyage.Id; } if (j.Activites != null) { ActivitesId = new List <int>(); foreach (Activite a in j.Activites) { ActivitesId.Add(a.Id); } } }
public JourDTO(Jour j) { Id = j.Id; BudgetJournee = j.BudgetJournee; Date = j.Date; if (j.Voyage != null) { VoyageId = j.Voyage.Id; } if (j.Activites != null) { ActivitesId = new List<int>(); foreach (Activite a in j.Activites) { ActivitesId.Add(a.Id); } } }
public IHttpActionResult PostJour(Jour jour) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Jours.Add(jour); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = jour.Id }, jour); }
public IHttpActionResult PostVoyage(Voyage voyage) { string id = User.Identity.GetUserId(); if (!ModelState.IsValid) { return BadRequest(ModelState); } int lenght = voyage.NbDeJour; for(int i = 0; i < lenght; i++) { Jour temp = new Jour(); temp.Voyage = voyage; temp.Date = voyage.DateTimeDebut.AddDays(i); temp.BudgetJournee = 0; db.Jours.Add(temp); voyage.Jours.Add(temp); } /*ApplicationUser user = db.Users.FirstOrDefault(u => u.Id == id); voyage.ApplicationUsers.Add(db.Users.FirstOrDefault(u => u.Id == id));*/ db.Voyages.Add(voyage); db.SaveChanges(); VoyageDTO dto = new VoyageDTO(voyage); return Ok(dto); }