private void SendSubscribtionNotification(IAbonnementProjet newAbo)
        {
            int delayNotif = CovCakeConfiguration.SubscriptionNotificationDelay;

            //TODO: a tester dans un contexte de charge importante (meme si yaura pas 10000 subscribtion en meme temps)
            //delayNotif = 10;
            DelayedTaskExecuter.ExecuteLaterAsync(delayNotif, (obj, timedOut) =>
            {
                IAbonnementProjet abo = obj as IAbonnementProjet;
                //Apres le delay on verifie si le mec est toujour bien inscrit et on envoi le mail
                lock (obj)
                {
                    if (abo.UserProfile.ParticipeA(abo.ProjetId))
                    {
                        try
                        {
                            CovCakeMailer.SendProjectSubscribtionNotify(abo);
                            CovCakeMailer.SendFriendsProjectSubscribNotify(abo);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }, newAbo);
        }
        /// <summary>
        /// Réalise l'inscription
        /// </summary>
        /// <param name="projetId"></param>
        /// <returns></returns>
        private IAbonnementProjet MakeSubscribtion(Guid UserId, int projetId)
        {
            //Si le mec est déja inscrit
            //au cas ou il refresh ou force en entrant l'url
            if (Data.AbonnementProjetDataAccess.GetAbonnement(UserId, projetId) != null)
            {
                return(null);
            }
            IAbonnementProjet abo = Data.AbonnementProjetDataAccess.CreateAbonnement();

            abo.DateAbonnement = DateTime.Now;
            abo.UserId         = UserId;
            abo.ProjetId       = projetId;

            IProjet proj = Data.ProjetDataAccess.GetProjet(projetId);

            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    proj.UserAbonnesEntitySet.Add((cov_AbonnementProjet)abo);
                    Data.ProjetDataAccess.SubmitChanges();
                    trans.Complete();
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(abo);
        }
        public ActionResult UnSubscribe(int projetId)
        {
            //IProjet proj = Data.ProjetDataAccess.GetProjet(projetId);
            IAbonnementProjet abo = Data.AbonnementProjetDataAccess.GetAbonnement(this.CurrentUserId, projetId);

            if (abo == null)
            {
                ViewData["ErrorMsg"] = "Le voyage concerné n'éxiste pas, impossible d'effectuer la desinscription";
                return(View("Error"));
            }

            //int pId = projetId;
            //Envoi de mail différé de

            bool succeed = MakeUnSubscribtion(abo);

            if (succeed)
            {
                this.SendProjetResignNotification(abo);
                TempData["ViewInfos"] = "Vous avez quitter le voyage " + abo.Projet.GetShortDisplayName();
                return(RedirectToAction("Index", new { projetId = abo.ProjetId }));
            }
            else
            {
                this.ModelState.AddModelError("_FORM", "La désinscription au voyage " + abo.Projet.GetShortDisplayName() + " à échoué ");
                TempData[GetModelErrorAttribute.MODEL_STATE_DICTIONARY_DEFAULT_KEY] = this.ModelState;
                return(RedirectToAction("Index", new { projetId = abo.ProjetId }));
            }
        }
        public ActionResult Subscribe(int projetId)
        {
            IAbonnementProjet newAbo = MakeSubscribtion(CurrentUser.UserId, projetId);
            int pId = projetId;
            int notifyDelayMinutes = CovCakeConfiguration.SubscriptionNotificationDelay / 60;

            if (newAbo != null)
            {
                //Envoi de mail différé, de XX secondes. XX == CovCakeConfiguration.SubscriptionNotificationDelay
                this.SendSubscribtionNotification(newAbo);
                string[] infoMessage =
                {
                    "Vous avez maintenant rejoint le voyage " + newAbo.Projet.GetShortDisplayName(),
                    "Un email de notification sera envoyé à " + newAbo.Projet.OwnerUserProfile.DisplayName + " dans " + notifyDelayMinutes + " minutes si vous participez toujours au voyage "
                };
                TempData["ViewInfos"] = infoMessage;
                return(RedirectToAction("Index", new { projetId = pId }));
            }
            else
            {
                this.ModelState.AddModelError("_FORM", "L'inscription à ce voyage à échoué");
                TempData[GetModelErrorAttribute.MODEL_STATE_DICTIONARY_DEFAULT_KEY] = this.ModelState;
                return(RedirectToAction("Index", new { projetId = pId }));
            }
            // Data.s
        }
Exemple #5
0
        /// <summary>
        /// Indique si User participe au projet projId
        /// </summary>
        /// <param name="user"></param>
        /// <param name="projId"></param>
        /// <returns></returns>
        public static bool ParticipeA(this IUserProfile user, int projId)
        {
            CovCakeData data = CovCake.DataProvider;                                                    // new CovCakeData();

            IAbonnementProjet abo = data.AbonnementProjetDataAccess.GetAbonnement(user.UserId, projId); //data.AbonnementProjetDataAccess.GetAllAbonnementsOf(user.UserId).Where(a => a.ProjetId == proj.IdProjet);

            return(abo != null);
        }
Exemple #6
0
        public bool SendFriendsProjectSubscribNotify(IAbonnementProjet newAbo)
        {
            const string templateName = "ProjectFriendSubscribNotify.htm";

            try
            {
                IQueryable <IAbonnementProjet> otherAboList = newAbo.Projet.UserAbonnes;
                IUserProfile toOwner = newAbo.Projet.OwnerUserProfile;
                IUserProfile fromSubscriber = newAbo.UserProfile;
                bool         IsHTML = templateName.Contains(".htm");
                string       siteName = CovCakeConfiguration.SiteName;
                string       from = CovCakeConfiguration.SiteNotifierEmail;
                string       fromEmailName = siteName;
                string       toEmail, toDisplayName;
                string       subject = "CoVoyage.net : " + fromSubscriber.PrenomNom + " vous rejoint sur un voyage";

                string body = this.LoadMailTemplate(templateName);

                string subscriberUrl = this.RefController.Url.CovCakeActionUrl("Index", "User", new { userId = toOwner.UserId });
                string ProfileLink   = "<a href='" + subscriberUrl + "' >" + fromSubscriber.PrenomNom + "</a>";

                string ProjetUrl  = this.RefController.Url.CovCakeActionUrl("Index", "Projets", new { projetId = newAbo.ProjetId });
                string ProjetLink = "<a href='" + ProjetUrl + "' >" + newAbo.Projet.GetLongDisplayName() + "</a>";

                int nbSubs = otherAboList.Count() + 1;
                body = body.Replace("#PROJETLONGNAMELINK#", ProjetLink);
                body = body.Replace("#SUBSCRIBERNAMELINK#", ProfileLink);
                body = body.Replace("#NBSUBSCRIBERS#", nbSubs.ToString());

                foreach (var abo in otherAboList)
                {
                    if (newAbo.ProjetId == abo.ProjetId && newAbo.UserId == abo.UserId)
                    {
                        continue;
                    }

                    toEmail       = abo.UserProfile.Email;
                    toDisplayName = abo.UserProfile.Prenom;

                    body = body.Replace("#DISPLAYNAME#", toDisplayName);

                    this.SendMailAsync(new MailAddress(from, fromEmailName), toEmail, subject, body, IsHTML);
                }
            }
            catch (Exception ex)
            {
                CovCake.Log.Exception.cError("SendFriendsProjectSubscribNotify error", ex);
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Réalise la désinscription
        /// </summary>
        /// <param name="abo"></param>
        /// <returns></returns>
        private bool MakeUnSubscribtion(IAbonnementProjet abo)// Guid UserId ,int projetId)
        {
            try
            {
                Data.AbonnementProjetDataAccess.DeleteAbonnement(abo);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
            //IProjet proj = Data.ProjetDataAccess.GetProjet(projetId);

            //IAbonnementProjet abo = Data.AbonnementProjetDataAccess.GetAbonnement(UserId, projetId);
        }
Exemple #8
0
        public bool SendProjectResignNotify(IAbonnementProjet abo)
        {
            const string templateName = "ProjectResignNotify.htm";

            try
            {
                IUserProfile toUser        = abo.Projet.OwnerUserProfile;
                IUserProfile fromUser      = abo.UserProfile;
                bool         IsHTML        = templateName.Contains(".htm");
                string       siteName      = CovCakeConfiguration.SiteName;
                string       from          = CovCakeConfiguration.SiteNotifierEmail;
                string       fromEmailName = siteName;
                string       toEmail       = toUser.Email;
                string       subject       = "CoVoyage.net : " + fromUser.PrenomNom + " a quitté un de vos voyages";

                string subscriberUrl = this.RefController.Url.CovCakeActionUrl("Index", "User", new { userId = toUser.UserId });

                string ProfileLink = "<a href='" + subscriberUrl + "' >" + fromUser.PrenomNom + "</a>";

                string ProjetUrl  = this.RefController.Url.CovCakeActionUrl("Index", "Projets", new { projetId = abo.ProjetId });
                string ProjetLink = "<a href='" + ProjetUrl + "' >" + abo.Projet.GetLongDisplayName() + "</a>";

                string body = this.LoadMailTemplate(templateName);

                body = body.Replace("#DISPLAYNAME#", toUser.Prenom);
                body = body.Replace("#PROJETLONGNAMELINK#", ProjetLink);

                body = body.Replace("#SUBSCRIBERNAMELINK#", ProfileLink);

                MailAddress fromAddress = new MailAddress(from, fromEmailName);
                //   this.To.Add(new MailAddress(email));
                this.SendMailAsync(fromAddress, toEmail, subject, body, IsHTML);
            }
            catch (Exception ex)
            {
                CovCake.Log.Exception.cError(string.Format("{0} userid={1}", "SendProjectResignNotify", CovCake.GetCurrentUserId().ToString()), ex);
                return(false);
            }
            return(true);
        }
Exemple #9
0
        public bool SendProjectSubscribtionNotify(IAbonnementProjet abo)
        {
            const string templateName = "ProjectSubscribtionNotify.htm";

            try
            {
                bool         IsHTML         = templateName.Contains(".htm");
                IUserProfile toOwner        = abo.Projet.OwnerUserProfile;
                IUserProfile fromSubscriber = abo.UserProfile;

                string      FromEMAILNAME = CovCakeConfiguration.SiteName;
                string      FromEMAIL     = CovCakeConfiguration.SiteNotifierEmail;
                MailAddress FromADDRESS   = new MailAddress(FromEMAIL, FromEMAILNAME);

                string ToEMAIL = toOwner.Email;
                string SUBJECT = "CoVoyage.net : " + fromSubscriber.PrenomNom + " a rejoint un de vos voyages";

                string subscriberUrl = this.RefController.Url.CovCakeRouteUrl(CovCake.Routes.USERINDEX, new { userId = toOwner.UserId.Shrink() });
                string ProfileLink   = "<a href='" + subscriberUrl + "' >" + fromSubscriber.PrenomNom + "</a>";

                string ProjetUrl  = this.RefController.Url.CovCakeRouteUrl(CovCake.Routes.PROJETINDEX, new { projetId = abo.ProjetId });
                string ProjetLink = "<a href='" + ProjetUrl + "' >" + abo.Projet.GetLongDisplayName() + "</a>";
                string MAILBODY   = this.LoadMailTemplate(templateName);

                var ReplaceArray = new Dictionary <string, string>();
                ReplaceArray["#DISPLAYNAME#"]        = toOwner.Prenom;
                ReplaceArray["#PROJETLONGNAMELINK#"] = ProjetLink;
                ReplaceArray["#SUBSCRIBERNAMELINK#"] = ProfileLink;
                MAILBODY = MAILBODY.Replace(ReplaceArray);

                this.SendMailAsync(FromADDRESS, ToEMAIL, SUBJECT, MAILBODY, IsHTML);
            }
            catch (Exception ex)
            {
                CovCake.Log.Exception.cError("SendProjectSubscribtionNotify error", ex);
                return(false);
            }
            return(true);
        }
        private void SendProjetResignNotification(IAbonnementProjet abo)
        {
            CovCakeMailer.SendProjectResignNotify(abo);

            /*
             * int delayNotif = 30;
             * DelayedTaskExecuter.ExecuteLaterAsync(delayNotif, (obj, timedOut) =>
             * {
             *  //Apres le delay on verifie si le mec est toujour bien inscrit et on envoi le mail
             *  lock (obj)
             *  {
             *          try
             *          {
             *              CovCakeMailer.SendProjectResignNotify(abo);
             *          }
             *          catch (Exception)
             *          {
             *          }
             *  }
             *
             * }, abo);
             * */
        }
 public void DeleteAbonnement(IAbonnementProjet abo)
 {
     _dataContext.cov_AbonnementProjets.DeleteOnSubmit((cov_AbonnementProjet)abo);
     _dataContext.SubmitChanges();
 }