/// <summary>
        /// Updates a message template
        /// </summary>
        /// <param name="messageTemplate">Message template</param>
        public virtual void Update(MessageTemplate messageTemplate)
        {
            if (messageTemplate == null)
                throw new ArgumentNullException("messageTemplate");

            messageTemplateRepository.Update(messageTemplate);

            cacheManager.RemoveByPattern(MESSAGETEMPLATES_PATTERN_KEY);

            //event notification
            eventPublisher.EntityUpdated(messageTemplate);
        }
 private EmailAccount GetEmailAccountOfMessageTemplate(MessageTemplate messageTemplate, Guid languageId)
 {
     var emailAccounId = messageTemplate.GetLocalized(mt => mt.EmailAccountId, languageId);
     var emailAccount  = emailAccountService.GetById(emailAccounId);
     if (emailAccount  == null)
         emailAccount  = emailAccountService.GetById(emailAccountSettings.DefaultEmailAccountId);
     if (emailAccount  == null)
         emailAccount  = emailAccountService.GetAll().FirstOrDefault();
     return emailAccount;
 }
        private Guid SendNotification(MessageTemplate messageTemplate,
            EmailAccount emailAccount, Guid languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName)
        {
            //retrieve localized message template data
            var bcc     = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId);
            var body    = messageTemplate.GetLocalized((mt) => mt.Body, languageId);

            //Replace subject and body tokens
            var subjectReplaced = tokenizer.Replace(subject, tokens, false);
            var bodyReplaced    = tokenizer.Replace(body, tokens, true);

            // retrieve the main localized master template
            var masterTemplate = GetLocalizedActiveMessageTemplate("Templates.Master", languageId);
            if (masterTemplate != null)
            {
                // set master template tokens
                var masterBody = masterTemplate.GetLocalized((mt) => mt.Body, languageId);
                messageTokenProvider.AddMasterTokens((IList<Token>)tokens, bodyReplaced);
                bodyReplaced = tokenizer.Replace(masterBody, tokens, true);
            }

            var email = new QueuedEmail()
            {
                Priority       = 5,
                From           = emailAccount.Email,
                FromName       = emailAccount.DisplayName,
                To             = toEmailAddress,
                ToName         = toName,
                CC             = string.Empty,
                Bcc            = bcc,
                Subject        = subjectReplaced,
                Body           = bodyReplaced,
                CreatedOn      = DateTime.UtcNow,
                EmailAccountId = emailAccount.RowId
            };

            queuedEmailService.Insert(email);
            return email.RowId;
        }
Example #4
0
 public static MessageTemplate ToEntity(this MessageTemplateModel model, MessageTemplate destination)
 {
     return Mapper.Map(model, destination);
 }