Пример #1
0
        public void CanGetTemplateByAlias()
        {
            EmailTemplate emailTemplate = _emailTemplateRepository.Save(GetTestEmailTemplate());

            EmailTemplate fetchedEmailTemplate = _emailTemplateRepository.GetByAlias(emailTemplate.Alias);

            Assert.AreEqual(emailTemplate.Id, fetchedEmailTemplate.Id);
        }
Пример #2
0
        public IEnumerable <Notification> NotifySubscribersViaEmail <T>(string notificationTypeAlias, string emailTemplateAlias, T model, long userId, long requestedBy,
                                                                        string source, string notes = null, int priority = 0, DateTime?notificationDate = null, bool useAlternateEmail = false)
        {
            NotificationType notificationType = _notificationTypeRepository.GetByAlias(notificationTypeAlias);

            if (!notificationType.IsQueuingEnabled)
            {
                return(null);
            }

            EmailTemplate emailTemplate = _emailTemplateRepository.GetByAlias(emailTemplateAlias);

            List <NotificationSubscriber> notificationSubscribers = _notificationSubscriberRepository.GetForNotificationType(notificationType.Id).ToList();

            notificationSubscribers.Add(GetUserToNotify(userId));

            if (useAlternateEmail)
            {
                var subscriber = GetAlternateEamilToNotify(userId);
                if (subscriber != null)
                {
                    notificationSubscribers.Add(subscriber);
                }
            }


            Email  fromEmail = _settings.EmailNotificationIssuedFrom;
            string fromName  = _settings.NameNotificationissuedFrom;

            var notifications = new List <Notification>();

            foreach (var notificationSubscriber in notificationSubscribers)
            {
                EmailMessage      formatMessage = _emailTemplateFormatter.FormatMessage(emailTemplate, model, notificationSubscriber.Email.ToString(), fromEmail.ToString(), fromName, emailTemplate.Id);
                NotificationEmail notificationEmail;
                if (notificationDate != null)
                {
                    notificationEmail = _notificationEmailFactory.CreateNotificationEmail(notificationType, notificationSubscriber, fromEmail,
                                                                                          fromName, formatMessage, source, notes, priority, requestedBy, userId, notificationDate.Value);
                }
                else
                {
                    notificationEmail = _notificationEmailFactory.CreateNotificationEmail(notificationType, notificationSubscriber, fromEmail,
                                                                                          fromName, formatMessage, source, notes, priority, requestedBy, userId);
                }

                Notification notification = _notificationRepository.Save(notificationEmail);
                notifications.Add(notification);
            }

            return(notifications);
        }
Пример #3
0
        public ActionResult ViewTemplate(string emailTemplateAlias, string emailSubject)
        {
            var emailTemplate = _emailTemplateRepository.GetByAlias(emailTemplateAlias);

            if (emailTemplate != null)
            {
                TempData["notificationTypeId"] = emailTemplate.NotificationTypeId;
            }
            return(View());
        }
Пример #4
0
        private string GetEmailMessagewithdummyData <T>(string emailTemplateAlias, string content, T model)
        {
            var emailBody = string.Empty;

            if (!string.IsNullOrEmpty(emailTemplateAlias))
            {
                EmailTemplate emailTemplate = _emailTemplateRepository.GetByAlias(emailTemplateAlias);

                emailBody = _emailTemplateFormatter.FormatContent(string.IsNullOrEmpty(content) ? emailTemplate.Body : content, model, emailTemplate.Id);
            }
            else if (!string.IsNullOrEmpty(content))
            {
                emailBody = _emailTemplateFormatter.FormatContent(content, model);
            }

            return(emailBody);
        }