public ActionResult Create([Bind(Include = "FormationID,DateDebut,DateFin,Intervenant,FormateurID,CommercialID")] SessionFormation sessionFormation)
        {
            // Incrémentation de l'indentifiant de la session de formation
            var idFormation = sessionFormation.FormationID;
            var aFormation  = _db.Formations.FirstOrDefault(f => f.FormationID == idFormation);

            if (aFormation.SessionsFormations.Count > 0)
            {
                var lastId = aFormation.SessionsFormations.Max(sf => sf.SessionFormationID);
                sessionFormation.SessionFormationID = lastId + 1;
            }
            else
            {
                sessionFormation.SessionFormationID = 1;
            }

            if (ModelState.IsValid)
            {
                _db.SessionsFormations.Add(sessionFormation);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CommercialID = new SelectList(_db.Commerciaux, "CommercialID", "NomComplet", sessionFormation.CommercialID);
            ViewBag.FormateurID  = new SelectList(_db.Formateurs, "FormateurID", "NomComplet", sessionFormation.FormateurID);
            ViewBag.FormationID  = new SelectList(_db.Formations, "FormationID", "ShortDescription", sessionFormation.FormationID);
            return(View(sessionFormation));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SessionFormation sessionFormation = _db.SessionsFormations.Find(id);

            _db.SessionsFormations.Remove(sessionFormation);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "SessionFormationID,FormationID,DateDebut,DateFin,Intervenant,FormateurID,CommercialID")] SessionFormation sessionFormation)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(sessionFormation).State = System.Data.Entity.EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CommercialID = new SelectList(_db.Commerciaux, "CommercialID", "NomUtilisateur", sessionFormation.CommercialID);
     ViewBag.FormateurID  = new SelectList(_db.Formateurs, "FormateurID", "Nom", sessionFormation.FormateurID);
     ViewBag.FormationID  = new SelectList(_db.Formations, "FormationID", "Reference", sessionFormation.FormationID);
     return(View(sessionFormation));
 }
        // GET: SessionFormations/Delete/5
        public ActionResult Delete(int?id, int?formationId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SessionFormation sessionFormation = _db.SessionsFormations.Find(id, formationId);

            if (sessionFormation == null)
            {
                return(HttpNotFound());
            }
            return(View(sessionFormation));
        }
        // GET: SessionFormations/Edit/5
        public ActionResult Edit(int?id, int?formationId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SessionFormation sessionFormation = _db.SessionsFormations.Find(id, formationId);

            if (sessionFormation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CommercialID = new SelectList(_db.Commerciaux, "CommercialID", "NomUtilisateur", sessionFormation.CommercialID);
            ViewBag.FormateurID  = new SelectList(_db.Formateurs, "FormateurID", "Nom", sessionFormation.FormateurID);
            ViewBag.FormationID  = new SelectList(_db.Formations, "FormationID", "Reference", sessionFormation.FormationID);
            return(View(sessionFormation));
        }