Пример #1
0
        public void SendObjectCreatedNotification(ObjectCreatedNotification notification, NotificationTypes type, string objectId, string absoluteObjectLink)
        {
            using (var session = actionsSessionFactory.CreateContext())
            {
                int[] actionTypes;
                if (type == NotificationTypes.IdeaCreated)
                {
                    actionTypes = new[] { (int)ActionTypes.IdeaCreated, (int)ActionTypes.IdeaEdited };
                }
                else if (type == NotificationTypes.IssueCreated)
                {
                    actionTypes = new[] { (int)ActionTypes.IssueCreated, (int)ActionTypes.IssueEdited };
                }
                else
                {
                    return;
                }

                var action =
                    session.Actions.FirstOrDefault(
                        a => a.ObjectId == objectId && actionTypes.Contains(a.ActionTypeId));
                if (action != null)
                {
                    SendObjectCreatedNotification(notification, action, type, absoluteObjectLink);
                }
            }
        }
Пример #2
0
 public void SendObjectCreatedNotification(ObjectCreatedNotification notification, Data.EF.Actions.Action action, NotificationTypes type, string absoluteObjectLink)
 {
     using (var userSession = usersSessionFactory.CreateContext())
     {
         var users = GetUsersToNotify(action);
         if (users.Any())
         {
             string subject = action.Subject;
             using (var session = noSqlSessionFactory())
             {
                 if (type == NotificationTypes.IdeaCreated)
                 {
                     var idea = session.GetAll <Data.MongoDB.Idea>().SingleOrDefault(i => i.Id == action.ObjectId);
                     if (idea != null)
                     {
                         subject         = idea.Subject;
                         idea.IsMailSent = true;
                         session.Update(idea);
                     }
                 }
                 else if (type == NotificationTypes.IssueCreated)
                 {
                     var issue =
                         session.GetAll <Data.MongoDB.Issue>().SingleOrDefault(i => i.Id == action.ObjectId);
                     if (issue != null)
                     {
                         subject          = issue.Subject;
                         issue.IsMailSent = true;
                         session.Update(issue);
                     }
                 }
             }
             notification.ObjectSubject = subject;
             notification.ObjectLink    = absoluteObjectLink;
             var not = GetNotification((int)type);
             notification.MessageTemplate = not.Message;
             notification.Subject         = not.Subject + ": " + subject;
             logger.Information(string.Format("Sending emails for {0} users", users.Count));
             foreach (
                 var user in users.SelectMany(u => u.UserEmails.Where(e => e.IsEmailConfirmed && e.SendMail)))
             {
                 notification.To            = user.Email;
                 notification.ToDisplayName = user.User.FirstName + " " + user.User.LastName;
                 notification.Execute();
             }
         }
     }
 }
Пример #3
0
 public IssueCommandHandler(NotificationService notificationService, ObjectCreatedNotification notification)
 {
     this.notificationService = notificationService;
     this.notification        = notification;
 }
 public SendObjectCreatedNotificationCommandHandler(ObjectCreatedNotification notification)
 {
     this.notification = notification;
 }
Пример #5
0
 public IdeaCommandHandler(NotificationService notificationService, ObjectCreatedNotification notification, IdeaResolvedNotification resolvedNotification)
 {
     this.notificationService  = notificationService;
     this.notification         = notification;
     this.resolvedNotification = resolvedNotification;
 }