Пример #1
0
        public ActiviteDTO(Activite a)
        {
            Id         = a.Id;
            HeureDebut = a.HeureDebut;
            HeureFin   = a.HeureFin;
            Cout       = a.Cout;
            Latitude   = a.Latitude;
            Longitude  = a.Longitude;

            if (a.Jour != null)
            {
                JourId = a.Jour.Id;
            }
            if (a.TransportUtilise != null)
            {
                TransportUtiliseId = a.TransportUtilise.Id;
            }
        }
Пример #2
0
        public ActiviteDTO(Activite a)
        {
            Id = a.Id;
            HeureDebut = a.HeureDebut;
            HeureFin = a.HeureFin;
            Cout = a.Cout;
            Latitude = a.Latitude;
            Longitude = a.Longitude;

            if (a.Jour != null)
            {
                JourId = a.Jour.Id;
            }
            if (a.TransportUtilise != null)
            {
                TransportUtiliseId = a.TransportUtilise.Id;
            }
        }
        public IHttpActionResult PostActivite(Activite activite)
        {
            //activite.HeureDebut = DateTime.Now;
            //activite.HeureFin = DateTime.Now;
            activite.Jour = db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id);

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id).Activites.Add(activite);
            db.Entry(db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id)).State = EntityState.Modified;

            db.Activites.Add(activite);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = activite.Id }, activite.Id);
        }
        public int PostActiviteCustom(int id, Activite activite)
        {
            activite.Jour = db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id);

            db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id).Activites.Add(activite);
            db.Entry(db.Jours.FirstOrDefault(j => j.Id == activite.Jour.Id)).State = EntityState.Modified;

            db.Activites.Add(activite);
            db.SaveChanges();

            return 0;
        }
        public IHttpActionResult PutActivite(int id, Activite activite)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }