Exemplo n.º 1
0
        private void ProcessEditionNotifications(KeyValuePair <EditionEntity, NotificationType> editionNotification, int itemIndex, int totalItemsCount)
        {
            var edition          = editionNotification.Key;
            var notificationType = editionNotification.Value;

            // NEEDLESS!
            // STEP 2: Does it REQUIRE a NOTIFICATION?
            var requires = EditionServices.RequiresNotification(edition, notificationType);

            if (requires)
            {
                // STEP 3: Does NOTIFICATION already EXIST?
                //if (!NotificationAlreadyExists(edition, notificationType))
                {
                    if (WebConfigHelper.PrimaryDirectorNotifications)
                    {
                        var recipients = WebConfigHelper.PrimaryDirectorNotificationsUseMockRecipients
                            ? WebConfigHelper.AdminEmails
                            : EventDirectorServices.GetRecipientEmails(edition);

                        // STEP 3: CREATE NOTIFICATION
                        CreateInAppNotification(edition, notificationType, recipients, null);

                        PushRealTimeInAppNotification(edition, notificationType, recipients, CurrentCedUser?.CurrentUser?.Email);

                        // STEP 4: SEND EMAIL
                        var notifAttr = notificationType.GetAttribute <NotificationAttribute>();
                        var buttonUrl = notificationType == NotificationType.EditionExistence
                            ? _editionHelper.GetEditionListUrl(edition.Event, notifAttr.Fragment)
                            : _editionHelper.GetEditionUrl(edition, notifAttr.Fragment);

                        var emailResult = SendEmailNotification(edition, notificationType, recipients, null, null, buttonUrl);

                        // STEP 5: LOG EMAIL
                        if (emailResult.Sent)
                        {
                            LogEmail(edition.EditionId, recipients, emailResult.ErrorMessage, null, notificationType.ToString());
                        }
                        else
                        {
                            LogEmail(edition.EditionId, WebConfigHelper.AdminEmails, emailResult.ErrorMessage, null, notificationType.ToString(), ActionType.NotificationEmailSendFailure);
                        }
                    }
                }
            }
        }