Пример #1
0
        public EmailQueue(Order order, EmailPreferences.NotificationTypes notificationType, string text, User user = null, string email = null)
        {
            SetDefaults();

            Order            = order;
            NotificationType = notificationType;
            Text             = text;
            User             = user;
            Email            = email;
        }
Пример #2
0
        public EmailQueueV2(Order order, EmailPreferences.NotificationTypes notificationType, string action, string details, User user = null, string email = null)
        {
            SetDefaults();

            Order            = order;
            NotificationType = notificationType;
            Action           = action;
            Details          = details;
            User             = user;
            Email            = email;
        }
        public static void ProcessEmails(IDbService dbService, EmailPreferences.NotificationTypes notificationType)
        {
            var sendEmail = CloudConfigurationManager.GetSetting("opp-send-email");

            //Don't execute unless email is turned on
            if (!string.Equals(sendEmail, "Yes", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine("No emails sent because opp-send-email is not set to 'Yes'");
                return;
            }

            using (var connection = dbService.GetConnection())
            {
                List <dynamic> pending = connection.Query(
                    "select Id, rtrim(ltrim([UserId])) as UserId, Email, OrderId, DateTimeCreated, Action, Details from EmailQueueV2 where Pending = 1 and NotificationType = @notificationType",
                    new { notificationType = notificationType.ToString() }).ToList();

                var pendingUserIds = pending.Where(x => x.UserId != null).Select(x => x.UserId).Distinct();

                List <dynamic> users = connection.Query("select distinct Id, Email from users where id in @ids",
                                                        new { ids = pendingUserIds.ToArray() }).ToList();

                #region Workgroup Notifications have a null User

                var workgroupNotifications = pending.Where(b => b.UserId == null).Select(a => a.Email).Distinct();

                foreach (var wEmail in workgroupNotifications)
                {
                    var pendingForUser = pending.Where(e => e.Email == wEmail).ToList();

                    var email = wEmail;

                    BatchEmail(connection, email, pendingForUser);
                }

                #endregion Workgroup Notifications have a null User

                #region Normal Email Notification, user will never be null

                foreach (var user in users)
                {
                    var pendingForUser = pending.Where(e => e.UserId == user.Id).ToList();

                    var email = user.Email;

                    BatchEmail(connection, email, pendingForUser);
                }

                #endregion Normal Email Notification, user will never be null
            }
        }