Example #1
0
        public VoyageDTO(Voyage v)
        {
            Id            = v.Id;
            Name          = v.Name;
            BudgetVoyage  = v.BudgetVoyage;
            DateTimeDebut = v.DateTimeDebut;
            NbDeJour      = v.NbDeJour;

            if (v.Jours != null)
            {
                JoursID = new List <int>();

                foreach (Jour j in v.Jours)
                {
                    JoursID.Add(j.Id);
                }
            }
        }
Example #2
0
        public VoyageDTO(Voyage v)
        {
            Id = v.Id;
            Name = v.Name;
            BudgetVoyage = v.BudgetVoyage;
            DateTimeDebut = v.DateTimeDebut;
            NbDeJour = v.NbDeJour;

            if (v.Jours != null)
            {
                JoursID = new List<int>();

                foreach (Jour j in v.Jours)
                {
                    JoursID.Add(j.Id);
                }
            }
        }
        public IHttpActionResult PutVoyage(int id, Voyage voyage)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != voyage.Id)
            {
                return BadRequest();
            }

            db.Entry(voyage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VoyageExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        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);
        }