Exemplo n.º 1
0
        public ActionResult INDUS_Post4(UserViewModel etudiants)
        {
            for (int i = 0; i < etudiants.Cne.Count; i++)
            {
                ConcourOral con = _context.CouncourOrals.Find(etudiants.Cne[i]);
                con.Classement = etudiants.Classement[i];
                _context.SaveChanges();
            }

            return(RedirectToAction("index"));
        }
Exemplo n.º 2
0
        public ActionResult INDUS_Post4()
        {
            GestionConcourDbContext db = new GestionConcourDbContext();

            var    NOTES = Request["etudiants.Classement"].ToString().Split(',');
            var    CNE   = Request["etudiants.Cne"].ToString().Split(',');
            String d;

            for (int i = 0; i < CNE.Length; i++)
            {
                d = CNE[i].ToString();
                ConcourOral con = db.CouncourOrals.Find(d);
                con.Classement = Int32.Parse(NOTES[i]);
                db.SaveChanges();
            }

            return(RedirectToAction("index"));
        }
        public ActionResult Register(Candidat candidat)
        {
            GestionConcourDbContext db = new GestionConcourDbContext();

            if (candidat.Niveau == 0)
            {
                ModelState.AddModelError("selectNiveau", "Selectionner un niveau");
            }
            var y = db.Candidats.Where(c => c.Cne == candidat.Cne).SingleOrDefault();

            if (y != null)
            {
                ModelState.AddModelError("UniqueCne", "Cne need to be unique");
            }
            var z = db.Candidats.Where(c => c.Cin == candidat.Cin).SingleOrDefault();

            if (z != null)
            {
                ModelState.AddModelError("UniqueCin", "Cin need to be unique");
            }
            var w = db.Candidats.Where(c => c.Email == candidat.Email).SingleOrDefault();

            if (w != null)
            {
                ModelState.AddModelError("UniqueEmail", "Email need to be unique");
            }


            if (ModelState.IsValid)
            {
                candidat.DateInscription = DateTime.Now;
                candidat.DateNaissance   = DateTime.Now;
                Random       random = new Random();
                const string pool   = "abcdefghijklmnopqrstuvwxyz0123456789";
                var          chars  = Enumerable.Range(0, 7)
                                      .Select(x => pool[random.Next(0, pool.Length)]);
                var charsMatricule = Enumerable.Range(0, 8)
                                     .Select(ww => pool[random.Next(0, pool.Length)]);
                candidat.Matricule = new string(charsMatricule.ToArray()).ToUpper();
                candidat.Password  = new string(chars.ToArray());
                candidat.Verified  = 0;
                candidat.Photo     = "icon.jpg";
                db.Candidats.Add(candidat);
                db.SaveChanges();

                Diplome            dip   = new Diplome();
                AnneeUniversitaire annUn = new AnneeUniversitaire();
                Baccalaureat       bac   = new Baccalaureat();
                ConcourEcrit       concE = new ConcourEcrit();
                ConcourOral        concO = new ConcourOral();


                //add row in diplome
                dip.Cne = candidat.Cne;
                db.Diplomes.Add(dip);
                db.SaveChanges();

                //add row in anne
                annUn.Cne = candidat.Cne;
                db.AnneeUniversitaires.Add(annUn);
                db.SaveChanges();

                //add row in bac
                bac.Cne = candidat.Cne;
                //bac.DateObtentionBac = DateTime.Now;
                db.Baccalaureats.Add(bac);
                db.SaveChanges();

                //add in concours ecrit
                concE.Cne = candidat.Cne;
                db.CouncourEcrits.Add(concE);
                db.SaveChanges();

                //add in concours oral
                concO.Cne = candidat.Cne;
                db.CouncourOrals.Add(concO);
                db.SaveChanges();


                var          fromAddress  = new MailAddress("*****@*****.**", "From ENSAS");
                var          toAddress    = new MailAddress(candidat.Email, "To Name");
                const string fromPassword = "******";
                const string subject      = "Récupération du mot de passe";
                //string body = "<a href=\"http://localhost:49969/Auth/Verify?cne="+candidat.Cne+" \">Link</a><br /><p> this is the password : "******"</p>";
                string body = "<div class=\"container\"><div class=\"row\"><img src=\"https://lh3.googleusercontent.com/proxy/g_QnANEsQGJPGvR4haGBTi-kr2n32DU-eArBRKuJWtpgPCHQbz-RINzL6FzIc1TQs0a80Vfkaew6umTHHPQgHTE4l_g \" /></div><div class=\"row text-center\"><h2>Vous avez créer un compte dans la platforme d'acces au cycle d'ingénieur a ENSAS .</h2></div><div class=\"alert alert-danger\"><strong><span style=\"color:'red'\">Vous trouverez votre mot de pass au dessouss</span></strong><br></div><div class=\"row\"><div class=\"card\" style=\"width: 18rem;\"><div class=\"card-body\"><strong>Nom :</strong><span>" + candidat.Nom + "</span><br /><strong>Prenom : </strong><span>" + candidat.Prenom + "</span><br /><strong>CNE : </strong><span>" + candidat.Cne + "</span><br /><strong>CIN : </strong><span>" + candidat.Cin + "</span><br /><strong>Password : </strong><span>" + candidat.Password + "</span><br /></div></div></div></div>";


                var smtp = new SmtpClient
                {
                    Host           = "smtp.gmail.com",
                    Port           = 587,
                    EnableSsl      = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    Credentials    = new NetworkCredential(fromAddress.Address, fromPassword),
                    Timeout        = 60000
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    message.IsBodyHtml = true;
                    smtp.Send(message);
                }
                TempData["message"] = "Votre mot de passe est : '" + candidat.Password + "'." + " Vous le trouverez sur votre email aussi.";
                return(Redirect("Login"));
            }
            return(View(candidat));
        }