コード例 #1
0
ファイル: InterventionsController.cs プロジェクト: sb44/Mento
        public ActionResult RepartirContent(ObjRepartir resultat)
        {
            if (ModelState.IsValid)
            {
                var erreursMentore = new List <string>();
                foreach (string noMentore in resultat.ChoixMentores)
                {
                    if (!ValiderInscriptionMentore(resultat.Date, noMentore))
                    {
                        string nomMentore = "";
                        using (var db = new ApplicationDbContext())
                        {
                            Mentore mentore = db.Mentores.FirstOrDefault(f => f.No_Mentore == noMentore);

                            if (mentore != null)
                            {
                                nomMentore = mentore.NomComplet_Mentore;
                            }
                        }

                        if (nomMentore == "")
                        {
                            nomMentore = "inconnu";
                        }
                        erreursMentore.Add(nomMentore);
                    }
                }

                if (erreursMentore.Count == 0)
                {
                    EnregistrerTempsRepartir(resultat);
                    return(Json(new { success = true }));
                }
                else
                {
                    return(Json(new { success = false, msg = "Ces mentorés ne sont pas inscrits au service de mentorat : \n\n" + string.Join(", ", erreursMentore.ToArray()) }));
                }
            }



            return(Json(new { success = false }));
        }
コード例 #2
0
ファイル: Csc_ExtensionsMethodes.cs プロジェクト: sb44/Mento
        public static string EcrireMessage(Mentore mentore)
        {
            var myClient = new WebClient();
            //Il doit y avoir sur la première ligne des informations sur les images.
            //string strHTML = myClient.DownloadString(HttpContext.Server.MapPath("~/Content/Inscriptions/Courriel_Inscription.html"));

            //string strHTML = myClient.DownloadString(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Inscriptions/Courriel_Inscription.html"));
            string strHTML = Path.Combine(Startup.WebRootPath, "/Content/Inscriptions/Courriel_Inscription.html");

            strHTML = strHTML.Replace("<#:Nom>", mentore.NomComplet_Mentore);
            strHTML = strHTML.Replace("<#:Organisme>", mentore.Organisme_Mentore);
            strHTML = strHTML.Replace("<#:Courriel>", mentore.Courriel_Mentore);
            strHTML = strHTML.Replace("<#:Telephone>", mentore.Telephone_Mentore);
            strHTML = strHTML.Replace("<#:Objectifs>", mentore.Objectifs_Mentore);

            //strHTML=  HttpUtility.HtmlEncode(strHTML);

            return(strHTML);
        }
コード例 #3
0
ファイル: InterventionsController.cs プロジェクト: sb44/Mento
        public JsonResult ObtenirMentores()
        {
            string         iNoMentor = HttpContext.Session.GetString("intNoMentor").ToString(); // string iNoMentor =Session["intNoMentor"].ToString();
            List <Mentore> mentores  = ObtenirListeMentore(iNoMentor);
            var            pourJson  = new List <Mentore>();


            foreach (var monMentore in mentores)
            {
                if (monMentore.No_Mentore != "1") //n'est pas le "Sélectionner un mentoré.."
                {
                    var entity = new Mentore
                    {
                        No_Mentore     = monMentore.No_Mentore,
                        Nom_Mentore    = monMentore.Nom_Mentore,
                        Prenom_Mentore = monMentore.Prenom_Mentore
                    };
                    pourJson.Add(entity);
                }
            }

            return(Json(pourJson));
        }
コード例 #4
0
ファイル: InterventionsController.cs プロジェクト: sb44/Mento
        private List <Mentore> ObtenirListeMentore(string iNoMentor)
        {
            var lstDuMentor    = new List <Mentore>();
            var lstAutreMentor = new List <Mentore>();

            foreach (Mentore monMentore in db.Mentores.ToList().OrderBy(c => c.Prenom_Mentore).ThenBy(c => c.Nom_Mentore))
            {
                MentoratInscription inscription = monMentore.Inscriptions.Where(w => w.Mentor.NoMentor != "1" || w.Mentore.No_Mentore == "F1490F96-566E-4440-ABE1-11660546E914" || w.Mentore.No_Mentore == "FB0660F1-0EE6-4CA6-9D31-BA74B02CE204").OrderByDescending(o => o.Annee).FirstOrDefault(); //la dernière inscription
                Mentor mentorTmp;

                if (inscription != null)
                {
                    mentorTmp = inscription.Mentor;

                    if (mentorTmp != null && mentorTmp.NoMentor == "1" && monMentore.No_Mentore != "F1490F96-566E-4440-ABE1-11660546E914")
                    {
                        //pour filtrer les mentorés qui n'ont pas de mentor
                        mentorTmp = null;
                    }
                }
                else
                {
                    //mentorTmp = db.Mentors.OrderBy(o => o.NoMentor).First();
                    if (monMentore.No_Mentore == "1" || monMentore.No_Mentore == "FB0660F1-0EE6-4CA6-9D31-BA74B02CE204")
                    {
                        mentorTmp = db.Mentors.OrderBy(o => o.NoMentor).First();
                    }
                    else
                    {
                        mentorTmp = null;
                    }
                }

                if (mentorTmp != null)
                {
                    //on ne veut pas des mentorés pas encore assignés
                    var mentoreTmp = new Mentore
                    {
                        No_Mentore     = monMentore.No_Mentore,
                        Prenom_Mentore = monMentore.Prenom_Mentore,
                        Nom_Mentore    = monMentore.Nom_Mentore,
                        MentorMentore  = mentorTmp
                    };
                    if (mentoreTmp.MentorMentore.NoMentor == iNoMentor || mentoreTmp.MentorMentore.NoMentor == "1") //est le mentor ou est le mentore "sélectionner un mentoré.."
                    {
                        lstDuMentor.Add(mentoreTmp);
                    }
                    else
                    {
                        mentoreTmp.Nom_Mentore += " (" + mentoreTmp.MentorMentore.NomCompletMentor + ")";
                        lstAutreMentor.Add(mentoreTmp);
                    }
                }
            }



            if (lstAutreMentor != null)
            {
                lstDuMentor.AddRange(lstAutreMentor);
            }

            return(lstDuMentor);
        }
コード例 #5
0
ファイル: InscriptionsController.cs プロジェクト: sb44/Mento
        public ActionResult Confirmation(Mentore mentore)
        {
            ViewBag.Message = "Détails de la transaction.";

            return(View(mentore));
        }
コード例 #6
0
ファイル: InscriptionsController.cs プロジェクト: sb44/Mento
        public async Task <ActionResult> InformationsMentore(MentoratNetCore.ViewModels.Inscriptions.InformationsMentoreViewModel model)
        {
            if (ModelState.IsValid)
            {
                var  db = new ApplicationDbContext();
                bool boolChangerUtilisateur = false;
                bool boolChangerCourriel    = false;

                List <Mentore> lstMentores = db.Mentores.ToList();

                Mentore monMentore = lstMentores.FirstOrDefault(f => f.No_Mentore == model.NoMentore);


                if (monMentore != null)
                {
                    List <ApplicationUser> lstUsers  = db.Users.ToList();
                    ApplicationUser        monUser   = null;
                    ApplicationUser        userVerif = null;

                    monUser = lstUsers.FirstOrDefault(f => f.Id == monMentore.No_Mentore);

                    if (monUser != null)
                    {
                        //s'assurer que le courriel et l'username est en minuscule
                        model.CourrielMentore = model.CourrielMentore.ToLower();
                        model.UserName        = model.UserName.ToLower();

                        if (model.UserName != monUser.UserName)
                        {
                            if (monUser.Email != monUser.UserName)
                            {
                                userVerif = lstUsers.Where(w => w.Id != monUser.Id).FirstOrDefault(f => f.UserName == model.UserName || f.Email == model.UserName);

                                if (userVerif != null)
                                {
                                    //L'user name est déjà présent comme courriel ou utilisateur.
                                    ModelState.AddModelError("UserName", "Ce nom d'utilisateur est déjà utilisé.");
                                }
                                else
                                {
                                    boolChangerUtilisateur = true;
                                }
                            }
                            else
                            {
                                if (!User.IsInRole("GererUtilisateur"))
                                {
                                    //Il est seulement possible d'avoir un nom d'utilisateur différent du courriel si un admin a déjà fait la modification
                                    ModelState.AddModelError("UserName", "Votre nom d'utilisateur ne peut être différent de votre adresse courriel.");
                                }
                                else
                                {
                                    boolChangerUtilisateur = true;
                                }
                            }
                        }

                        if (model.CourrielMentore != monUser.Email)
                        {
                            userVerif = lstUsers.Where(w => w.Id != monUser.Id).FirstOrDefault(f => f.UserName == model.CourrielMentore || f.Email == model.CourrielMentore);

                            if (userVerif != null)
                            {
                                //Le courriel est déjà présent comme courriel ou utilisateur.
                                ModelState.AddModelError("CourrielMentore", "Ce courriel est déjà utilisé.");
                            }
                            else
                            {
                                boolChangerCourriel = true;

                                if (!boolChangerUtilisateur && monUser.Email == monUser.UserName)
                                {
                                    model.UserName         = model.CourrielMentore;
                                    boolChangerUtilisateur = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "Erreur!"); //l'utilisateur n'a pas été reconnu
                    }


                    if (ModelState.IsValid && monUser != null)
                    {
                        monMentore.Prenom_Mentore     = model.PrenomMentore;
                        monMentore.Nom_Mentore        = model.NomMentore;
                        monMentore.Organisme_Mentore  = model.Organisme_Mentore;
                        monMentore.Telephone_Mentore  = model.TelephoneMentore;
                        monMentore.Cellulaire_Mentore = model.CellulaireMentore;

                        monUser.PrenomUser = model.PrenomMentore;
                        monUser.NomUser    = model.NomMentore;

                        if (boolChangerUtilisateur)
                        {
                            monUser.UserName = model.UserName;
                        }

                        if (boolChangerCourriel)
                        {
                            monMentore.Courriel_Mentore = model.CourrielMentore;
                            monUser.Email = model.CourrielMentore;
                        }
                        db.SaveChanges();


                        if (boolChangerUtilisateur && !User.IsInRole("GererUtilisateur"))
                        {
                            //on déconnecte l'utilisateur.
                            //Microsoft.Owin.IOwinContext ow = Request.GetOwinContext();
                            //Microsoft.Owin.Security.IAuthenticationManager auth = ow.Authentication;
                            //auth.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                            await _signInManager.SignOutAsync();
                        }

                        return(Json(new { success = true, refresh = boolChangerUtilisateur, userName = monUser.UserName }));
                    }
                }
            }

            return(PartialView(model));
        }
コード例 #7
0
ファイル: Csc_ExtensionsMethodes.cs プロジェクト: sb44/Mento
        public static async Task Envoyercourriel(Mentore mentore, string message, string apiKey)
        {
            dynamic sg = new SendGridAPIClient(apiKey);



            //Mon object de courriel
            var monCourriel     = new Mail();
            var mesInformations = new Personalization();

            //De:
            var contactEmail = new Email();

            ///contactEmail.Address = "*****@*****.**";
            contactEmail.Address = "*****@*****.**";
            contactEmail.Name    = "Inscription Mentorat";
            monCourriel.From     = contactEmail;

            ////À:
            //for (int i = 0; i <= monMail.LesDestinataires.Count - 1; i++)
            //{
            //    contactEmail = new Email();
            //    contactEmail.Address = monMail.LesDestinataires[i];
            //    mesInformations.AddTo(contactEmail);
            //}

            //À:

            ///      contactEmail = new Email();
            ///      contactEmail.Address = "*****@*****.**";
            ///      mesInformations.AddTo(contactEmail);
            ///
            ///      contactEmail = new Email();
            ///      contactEmail.Address = "*****@*****.**";
            ///      mesInformations.AddCc(contactEmail);

            contactEmail         = new Email();
            contactEmail.Address = "*****@*****.**";
            mesInformations.AddTo(contactEmail);


            //if (monMail.LesCC != null)
            //{
            //    for (int i = 0; i <= monMail.LesCC.Count - 1; i++)
            //    {
            //        contactEmail = new Email();
            //        contactEmail.Address = monMail.LesCC[i];
            //        mesInformations.AddCc(contactEmail);
            //    }
            //}

            //contactEmail = new Email();
            //contactEmail.Address = "*****@*****.**";
            //mesInformations.AddCc(contactEmail);


            //CC:


            ////CCI:
            //for (int i = 0; i <= monMail.LesCCI.Count - 1; i++)
            //{
            //    contactEmail = new Email();
            //    contactEmail.Address = monMail.LesCCI[i];
            //    mesInformations.AddBcc(contactEmail);
            //}


            //Objet
            //monCourriel.Subject = "Ha oui!";
            mesInformations.Subject = "Nouvelle inscription au service de mentorat";

            monCourriel.AddPersonalization(mesInformations);

            //Message
            string strMsg  = HttpUtility.HtmlDecode(message);
            var    content = new Content();

            content.Type  = "text/html";
            content.Value = strMsg;
            monCourriel.AddContent(content);

            //for (int i = 0; i <= lstLiensImg.Count - 1; i++)
            //{
            //    //je permet seulement les .png
            //    if (lstLiensImg[i].IndexOf(".png") > 0)
            //    {
            //        string headerPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/Signatures/" + lstLiensImg[i]);
            //        var attch = new Attachment();
            //        byte[] imageArray = System.IO.File.ReadAllBytes(headerPath);
            //        string strAttachement = Convert.ToBase64String(imageArray);

            //        attch.Content = strAttachement;
            //        attch.Type = "image/png";
            //        attch.ContentId = lstLiensImg[i].Replace(".png", "");
            //        attch.Filename = lstLiensImg[i];
            //        attch.Disposition = "inline";
            //        monCourriel.AddAttachment(attch);
            //    }
            //}

            //désactivé pour ne pas envoyer de courriel
            dynamic response = await sg.client.mail.send.post(requestBody : monCourriel.Get());
        }