Example #1
0
        public bool Send(NotificationType notificationType, string subject, string body, string recipients)
        {
            var sendEmail = notificationType.GetAttribute <NotificationAttribute>().SendEmail;

            if (sendEmail)
            {
                subject  = _emailSubjectStart + subject;
                subject += WebConfigHelper.IsLocal ? " " + _emailSubjectMarkForLocal : (WebConfigHelper.IsTest ? " " + _emailSubjectMarkForTest : null);

                var notfAttr = notificationType.GetAttribute <NotificationAttribute>();

                if (notfAttr == null)
                {
                    throw new Exception("Notification Attribute not found!");
                }

                var editionMailTemplate = new EditionMailTemplate
                {
                    Recipients      = recipients,
                    Subject         = subject,
                    Body            = body,
                    ButtonText      = notfAttr.ButtonText,
                    PartialViewName = notfAttr.ViewName
                };

                var mailer = new UserMailer.UserMailer();
                mailer.Send(editionMailTemplate, notfAttr.PrivateEmail);
                return(true);
            }
            return(false);
        }
Example #2
0
        public IList <EditionEntity> GetEditionsToNotify(NotificationType notificationType)
        {
            IList <EditionEntity> editions;

            if (WebConfigHelper.IsLocal || WebConfigHelper.IsTest)
            {
                editions = EditionServices.GetEditionsByEvent(248);
            }
            else
            {
                var deviationInDays = WebConfigHelper.EditionNotificationDeviationInDays;
                if (notificationType.GetAttribute <NotificationAttribute>().CheckDaysType == NotificationAttribute.CheckDaysTypes.Passed)
                {
                    deviationInDays *= -1;
                }
                var checkDays = _emailNotificationHelper.GetCheckDays(notificationType).Select(x => x - deviationInDays).ToList();

                var minFinancialYear = WebConfigHelper.MinFinancialYear;
                var statuses         = Utility.Constants.DefaultValidEditionStatusesForCed;
                var eventTypes       = notificationType.GetAttribute <NotificationAttribute>().EventTypes.Select(x => x.GetDescription()).ToArray();
                var eventActivities  = Utility.Constants.ValidEventActivitiesToNotify;

                editions = EditionServices.GetEditionsByNotificationType(checkDays, null, notificationType, minFinancialYear, statuses, eventTypes, eventActivities);
            }

            return(editions);
        }
Example #3
0
        public string GetDescription(EditionEntity edition, NotificationType notificationType)
        {
            var url = notificationType == NotificationType.EditionExistence
                ? _editionHelper.GetEditionListUrl(edition.Event, notificationType.GetAttribute <NotificationAttribute>().Fragment)
                : _editionHelper.GetEditionUrl(edition, notificationType.GetAttribute <NotificationAttribute>().Fragment);
            var name = _editionHelper.GetNameWithEditionNo(edition);
            var link = $"<a href=\"{url}\" target=\"_blank\"><b>{name}</b></a>";
            var desc = notificationType.GetDescription();

            return(string.Format(desc, link));
        }
        /* EMAIL NOTIFICATION */
        public EmailResult SendEmailNotification(EditionEntity edition, NotificationType notificationType, string recipients, UserEntity actor, string body,
                                                 string buttonUrl, string unsubscribingUrl = null)
        {
            //if (string.IsNullOrWhiteSpace(recipients))
            //{
            //    var message = $"{notificationType} type of notification email could not be sent since edition {edition.EditionId} - {edition.EditionName} has no recipients.";
            //    var log = CreateInternalLog(message, actor);
            //    ExternalLogHelper.Log(log, LoggingEventType.Warning);
            //    return new EmailResult { Sent = false, ErrorMessage = message };
            //}

            if (WebConfigHelper.RemoveActorUserFromNotificationRecipients)
            {
                recipients = NotificationControllerHelper.RemoveCurrentUserFromRecipients(recipients, actor?.Email);
            }

            //if (string.IsNullOrWhiteSpace(recipients))
            //    return false;

            try
            {
                var recipientFullName = _editionHelper.GetRecipientFullName(edition);

                var sendEmailAttr = notificationType.GetAttribute <NotificationAttribute>().SendEmail;
                if (sendEmailAttr)
                {
                    var editionTranslation =
                        edition.EditionTranslations.SingleOrDefault(x => string.Equals(x.LanguageCode,
                                                                                       LanguageHelper.GetBaseLanguageCultureName(), StringComparison.CurrentCultureIgnoreCase));

                    var emailResult = _emailNotificationHelper.Send(edition, editionTranslation, notificationType, recipientFullName, body, recipients,
                                                                    buttonUrl, unsubscribingUrl);

                    //// EMAIL LOGGING
                    //if (sent)
                    //LogEmail(edition.EditionId, recipients, body, actor?.Email, notificationType.ToString());

                    return(emailResult);
                }
            }
            catch (Exception exc)
            {
                var log = CreateInternalLog(exc, actor);
                ExternalLogHelper.Log(log, LoggingEventType.Error);
            }

            return(new EmailResult {
                Sent = false, ErrorMessage = ""
            });
        }
Example #5
0
        public EmailResult Send(EditionEntity edition, EditionTranslationEntity editionTranslation, NotificationType notificationType,
                                string recipientFullName, string body, string recipients, string buttonUrl, string unsubscriptionUrl)
        {
            if (string.IsNullOrWhiteSpace(recipients))
            {
                var message = $"{notificationType} type of notification email could not be sent since edition {edition.EditionId} - {edition.EditionName} has no recipients.";
                return(new EmailResult {
                    Sent = false, ErrorMessage = message
                });
            }

            var sendEmail = notificationType.GetAttribute <NotificationAttribute>().SendEmail;

            if (sendEmail)
            {
                MvcMailMessage mailMessage = null;
                var            webLogoUrl  = EditionImageType.WebLogo.BlobFullUrl(editionTranslation);
                var            displayDate = DateHelper.GetDisplayDate(edition.StartDate, edition.EndDate);
                var            subject     = GetSubject(edition, notificationType);

                subject += WebConfigHelper.IsLocal ? " " + _emailSubjectMarkForLocal : (WebConfigHelper.IsTest ? " " + _emailSubjectMarkForTest : null);

                var notfAttr = notificationType.GetAttribute <NotificationAttribute>();

                if (notfAttr == null)
                {
                    throw new Exception("Notification Attribute not found!");
                }

                var editionMailTemplate = new EditionMailTemplate
                {
                    EditionId         = edition.EditionId,
                    EventId           = edition.EventId,
                    AxEventId         = edition.AxEventId,
                    EditionName       = edition.EditionName,
                    EventName         = edition.Event.MasterName,
                    WebLogoUrl        = webLogoUrl,
                    Recipients        = recipients,
                    RecipientFullName = recipientFullName,
                    DisplayDate       = displayDate,
                    VenueName         = editionTranslation.VenueName,
                    Subject           = subject,
                    Body              = body,
                    ButtonText        = notfAttr.ButtonText,
                    ButtonUrl         = buttonUrl,
                    UnsubscriptionUrl = unsubscriptionUrl,
                    GuideUrl          = WebConfigHelper.CedLogoUrl,
                    PartialViewName   = notfAttr.ViewName
                };

                var mailer = new UserMailer.UserMailer();
                mailMessage = mailer.Send(editionMailTemplate, notfAttr.PrivateEmail);
                return(new EmailResult {
                    Sent = true, ErrorMessage = ""
                });
            }

            return(new EmailResult {
                Sent = false, ErrorMessage = "Unknown error"
            });
        }