Ejemplo n.º 1
0
        private static void RemindSponsorship()
        {
            try
            {
                System.Console.WriteLine("---DEBUT RELANCE PARRAINAGE---");

                //Get list "Code parrainage" not activated, not expired and "filleul" want to receive email
                List<Sponsorship> lstSponsorships = Business.Souscription.SponsorshipBL.GetActiveSponsorshipCodes();

                //Si le filleul n'a pas souscrit, renvoyer l'e-mail tous les 30 jours.
                foreach (var sponsorship in lstSponsorships)
                {
                    //multiple de 30 ?
                    int diff = (DateTime.Now - sponsorship.CreatedDate).Days;
                    if (diff != 0 && diff % 30 == 0)
                    {
                        //Send mail to filleul
                        if (!string.IsNullOrEmpty(sponsorship.EmailFilleul))
                        {                           
                            bool isSent = Business.Souscription.SponsorshipBL.SendEmailToFilleul(sponsorship);
                         
                            System.Console.WriteLine(@"Envoi email à l'utilisateur '{0} - {1} {2}' : {3}", sponsorship.EmailFilleul, sponsorship.NameFilleul, sponsorship.FirstnameFilleul, (isSent) ? "OK" : "KO");
                            
                            //Creation log envoi parrainage
                            if (isSent)
                            {
                                ReminderLog reminder = new ReminderLog()
                                {
                                    DateCreated = DateTime.Today,
                                    Email = sponsorship.EmailFilleul,
                                    idUser = null,
                                    IsAutomatic = true, //service auto
                                    DocumentType = Upsilab.Business.Souscription.SponsorshipBL.Parrainage,
                                };

                                ReminderLogBL.AddReminder(reminder);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.AppendException(ex);
            }

            System.Console.WriteLine("---FIN RELANCE PARRAINAGE---");
        }
Ejemplo n.º 2
0
        private static void EnvoiMailExpirationLicence()
        {

            System.Console.WriteLine("---DEBUT ENVOI MAIL RELANCE LICENCES EXPIREES---");
            try
            {
                string sFrom = Upsilab.Business.Utility.ConfigurationManager.EmailFrom;
                string sTo = string.Empty;
                string sCC = string.Empty;
                string sSubject = @"Renouvellement de vos licences Upsideo";
                string sMsg = string.Empty;
                bool isSent = false;
                List<User> userAdminList = new List<User>();
                using (UpsilabEntities db = new UpsilabEntities())
                {
                    //liste des administrateurs centrals
                    DateTime datetimelimite = DateTime.Now.AddDays(30);
                    userAdminList = (from uc in db.User
                                     join f in db.FirmInstitution on uc.idUser equals f.idUserCreated
                                     join fa in db.FirmInstitutionAdviser on f.idFirmInstitution equals fa.idFirmInstitutionParent
                                     join u in db.User on fa.idUser equals u.idUser
                                     where ((u.License != null
                                            && u.License.DateExpired >= DateTime.Now
                                            && u.License.DateExpired <= datetimelimite)
                                            || (u.License1 != null
                                            && u.License1.DateExpired >= DateTime.Now
                                            && u.License1.DateExpired <= datetimelimite)) && uc.ReceiveLicenseRemind == true
                                     select uc).Distinct().ToList();

                    List<User> userList = null;
                    foreach (User userAdminNow in userAdminList)
                    {                        
                        //test la deriniere date d'envoie mail aux useradmin
                        bool isMailTosend = true;
                        List<ReminderLog> lstremender = ReminderLogBL.GetListReminderLog(userAdminNow.idUser, UserBL.LicenseExpired);
                        
                        if (lstremender != null && lstremender.Count > 0)
                        {
                            ReminderLog rd = lstremender.FirstOrDefault();                            
                            int diffDay = (DateTime.Today - rd.DateCreated).Days;                            
                            isMailTosend = (diffDay >= 3)? true : false; //Envoi tous les 3jours (mais il se peut que l'envoi echoue et on prend >)                           
                        }
                        
                        isSent = false;
                        
                        if (isMailTosend)
                        {
                            sTo = userAdminNow.UserEmail;
                            sMsg = string.Empty;
                            sMsg += @"<p>Bonjour,</p><p>Nous souhaitons vous informer que les licences des utilisateurs ci-dessous arrivent bientôt à expiration.</p>";

                            //liste des users pour chaque administrateur central
                            userList = new List<User>();
                            userList = (from uc in db.User
                                        join f in db.FirmInstitution on uc.idUser equals f.idUserCreated
                                        join fa in db.FirmInstitutionAdviser on f.idFirmInstitution equals fa.idFirmInstitutionParent
                                        join u in db.User on fa.idUser equals u.idUser
                                        where uc.idUser == userAdminNow.idUser
                                        select u).Distinct().ToList();
                            sMsg += @"<ul>";
                            foreach (User userNow in userList)
                            {
                                if (userNow.License != null)
                                {
                                    //System.Console.WriteLine(string.Format(@"LAB Licence N° {0} {1} {2} {3}", userNow.License.LicenseKey, userNow.UserName, userNow.UserFirstName, userNow.License.DateExpired.ToString()));
                                    sMsg += string.Format(@"<li>LAB Licence N° {0} {1} {2} {3}</li>", userNow.License.LicenseKey, userNow.UserName, userNow.UserFirstName, userNow.License.DateExpired.ToString());

                                }
                                if (userNow.License1 != null)
                                {
                                    //System.Console.WriteLine(string.Format(@"Recueil Licence N° {0} {1} {2} {3}", userNow.License1.LicenseKey, userNow.UserName, userNow.UserFirstName, userNow.License1.DateExpired.ToString()));
                                    sMsg += string.Format(@"<li>Recueil Licence N° {0} {1} {2} {3}</li>", userNow.License1.LicenseKey, userNow.UserName, userNow.UserFirstName, userNow.License1.DateExpired.ToString());
                                }

                            }
                            //end list user
                            sMsg += @"</ul>";
                            sMsg += @"<p>Afin de continuer à profiter de vos outils, nous vous invitons à renouveler vos licences dès maintenant en suivant la procédure suivante :</p><p>• Connectez-vous sur votre espace UPSIDEO, cliquez sur ""Souscrire > Un renouvellement de licence"".</p><p>Cordialement,</p>Le service client d’UPSIDEO<br/>[email protected]";
                        
                            isSent = UserBL.SendAlertEmailExpirationLicence(userAdminNow, sFrom, sTo, sSubject, sMsg);
                        }                       

                        //Creation log Licence expiré
                        if (isSent)
                        {
                            ReminderLog reminder = new ReminderLog()
                            {
                                DateCreated = DateTime.Today,
                                Email = userAdminNow.UserEmail,
                                idUser = userAdminNow.idUser,                               
                                IsAutomatic = true, //service auto
                                DocumentType = UserBL.LicenseExpired,
                            };                         

                            ReminderLogBL.AddReminder(reminder);
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                Log.AppendException(ex);
            }

            System.Console.WriteLine("---FIN ENVOI MAIl LICENCES EXPIREES---");
        }