Beispiel #1
0
        public ActionResult Create([Bind(Include = "id_Pers,id_Sexe,id_TypeUsag,Nom,Prenom,Matricule,MP,ConfirmPassword,Courriel,Telephone,DateNais")] Personne personne, int?page)
        {
            var etuProg = new PersonneEtuProgParent();

            personne.id_TypeUsag = 1;
            personne.Actif       = true;
            personne.Telephone   = SachemIdentite.FormatTelephone(personne.Telephone);
            personne.Matricule   = AnneePremiersCaracteres + personne.Matricule;
            etuProg.personne     = personne;

            ViewBag.id_Sexe      = Db.p_Sexe;
            ViewBag.Selected     = 0;
            ViewBag.id_TypeUsag  = new SelectList(Db.p_TypeUsag, "id_TypeUsag", "TypeUsag");
            ViewBag.id_Programme = new SelectList(Db.ProgrammeEtude.Where(x => x.Actif), "id_ProgEtu", "CodeNomProgramme");
            ViewBag.id_Session   = new SelectList(Db.Session, "id_Sess", "NomSession");

            Valider(etuProg.personne);
            if (etuProg.personne.MP == null)
            {
                ModelState.AddModelError("Mot de passe", "Veuillez entrer un mot de passe");
                TempData["Echec"] = "Veuillez entrer un mot de passe";
            }
            else
            {
                if (ConfirmeMdp(personne.MP, personne.ConfirmPassword) == false)
                {
                    return(View(etuProg));
                }
            }

            var etuprog = new EtuProgEtude();

            if (Request.Form["id_Programme"] != "" && Request.Form["id_Session"] != "")
            {
                etuprog.id_ProgEtu = int.Parse(Request.Form["id_Programme"]);
                etuprog.id_Sess    = int.Parse(Request.Form["id_Session"]);
                etuprog.id_Etu     = personne.id_Pers;
                Db.EtuProgEtude.Add(etuprog);
            }

            if (ModelState.IsValid)
            {
                etuProg.personne.MP = SachemIdentite.EncrypterChaine(etuProg.personne.MP);
                etuProg.personne.ConfirmPassword = SachemIdentite.EncrypterChaine(etuProg.personne.ConfirmPassword);
                Db.Personne.Add(etuProg.personne);
                Db.SaveChanges();
                personne.Telephone = SachemIdentite.RemettreTel(personne.Telephone);

                TempData["Success"] = Messages.EtudiantEnregistre(personne.Matricule7);

                return(RedirectToAction("Index"));
            }
            return(View(etuProg));
        }
Beispiel #2
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Personne personne = Db.Personne.Find(id);

            if (personne == null)
            {
                return(HttpNotFound());
            }

            if (personne.Telephone != null)
            {
                personne.Telephone = SachemIdentite.RemettreTel(personne.Telephone);
            }

            var programmes = from d in Db.EtuProgEtude
                             where d.id_Etu == personne.id_Pers
                             orderby d.ProgrammeEtude.Code
                             select d;

            ViewBag.id_Sexe      = Db.p_Sexe;
            ViewBag.Selected     = personne.id_Sexe;
            ViewBag.id_TypeUsag  = new SelectList(Db.p_TypeUsag, "id_TypeUsag", "TypeUsag", personne.id_TypeUsag);
            ViewBag.id_Programme = new SelectList(Db.ProgrammeEtude.Where(x => x.Actif), "id_ProgEtu", "CodeNomProgramme");
            ViewBag.id_Session   = new SelectList(Db.Session, "id_Sess", "NomSession");
            var etuProg = new PersonneEtuProgParent
            {
                personne   = personne,
                EtuProgEtu = programmes.ToList()
            };

            return(View(etuProg));
        }
Beispiel #3
0
        public ActionResult Edit([Bind(Include = "id_Pers,id_Sexe,id_TypeUsag,Nom,Prenom,NomUsager,Matricule7,MP,ConfirmPassword,Courriel,Telephone,DateNais,Actif")] Personne personne)
        {
            var etuProg = new PersonneEtuProgParent();

            personne.id_TypeUsag = 1;
            personne.Telephone   = SachemIdentite.FormatTelephone(personne.Telephone);
            etuProg.personne     = personne;
            const string message = "Le mot de passe doit contenir 6 caratères";

            var etuprog = new EtuProgEtude();

            var prog = from d in Db.EtuProgEtude
                       where d.id_Etu == etuProg.personne.id_Pers
                       orderby d.ProgrammeEtude.Code
                       select d;

            etuProg.EtuProgEtu = prog.ToList();
            if (Request.Form["id_Programme"] != "" && Request.Form["id_Session"] != "" && ConfirmeMdp(personne.MP, personne.ConfirmPassword))
            {
                etuprog.id_ProgEtu = int.Parse(Request.Form["id_Programme"]);
                etuprog.id_Sess    = int.Parse(Request.Form["id_Session"]);
                etuprog.id_Etu     = personne.id_Pers;
                Db.EtuProgEtude.Add(etuprog);
                Db.SaveChanges();
            }
            if (ConfirmeMdp(personne.MP, personne.ConfirmPassword))
            {
                if (personne.MP != null && personne.MP.Length < 6)
                {
                    ModelState.AddModelError("ConfirmPassword", message);
                    TempData["Echec"] = message;
                }
                else
                {
                    if (personne.MP != null && personne.ConfirmPassword != null)
                    {
                        etuProg.personne.MP = SachemIdentite.EncrypterChaine(etuProg.personne.MP);
                        etuProg.personne.ConfirmPassword = SachemIdentite.EncrypterChaine(etuProg.personne.ConfirmPassword);
                    }
                    else
                    {
                        var mdp = from c in Db.Personne
                                  where (c.id_Pers == personne.id_Pers)
                                  select c.MP;
                        personne.MP = mdp.SingleOrDefault();
                        personne.ConfirmPassword = personne.MP;
                    }
                }
            }

            if (ModelState.IsValid)
            {
                Db.Entry(etuProg.personne).State = EntityState.Modified;
                Db.SaveChanges();
                TempData["Success"] = Messages.EtudiantModifie(personne.NomPrenom);
                return(RedirectToAction("Index"));
            }

            ViewBag.id_Sexe      = Db.p_Sexe;
            ViewBag.Selected     = etuProg.personne.id_Sexe;
            ViewBag.id_TypeUsag  = new SelectList(Db.p_TypeUsag, "id_TypeUsag", "TypeUsag", etuProg.personne.id_TypeUsag);
            ViewBag.id_Programme = new SelectList(Db.ProgrammeEtude.Where(x => x.Actif), "id_ProgEtu", "CodeNomProgramme");
            ViewBag.id_Session   = new SelectList(Db.Session, "id_Sess", "NomSession");
            return(View(etuProg));
        }