Ejemplo n.º 1
0
        /// <summary>
        /// Sends a private message notification
        /// </summary>
        /// <param name="privateMessage">Private message</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendPrivateMessageNotification(PrivateMessage privateMessage, int languageId)
        {
            if (privateMessage == null)
            {
                throw new ArgumentNullException("privateMessage");
            }

            var messageTemplate = GetLocalizedActiveMessageTemplate("User.NewPM", languageId);

            if (messageTemplate == null)
            {
                return(0);
            }

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddSiteTokens(tokens);
            _messageTokenProvider.AddPrivateMessageTokens(tokens, privateMessage);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);
            var toEmail      = privateMessage.ToUser.Email;
            var toName       = privateMessage.ToUser.GetFullName();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends a private message notification
        /// </summary>
        /// <param name="privateMessage">Private message</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendPrivateMessageNotification(PrivateMessage privateMessage, int languageId)
        {
            if (privateMessage == null)
            {
                throw new ArgumentNullException("privateMessage");
            }

            var store = _storeService.GetStoreById(privateMessage.StoreId) ?? _storeContext.CurrentStore;

            var messageTemplate = GetActiveMessageTemplate(MessageTemplateSystemNames.PrivateMessageNotification, store.Id);

            if (messageTemplate == null)
            {
                return(0);
            }

            //email account
            var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

            //tokens
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);
            _messageTokenProvider.AddPrivateMessageTokens(tokens, privateMessage);
            _messageTokenProvider.AddCustomerTokens(tokens, privateMessage.ToCustomer);

            //event notification
            _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

            var toEmail = privateMessage.ToCustomer.Email;
            var toName  = privateMessage.ToCustomer.GetFullName();

            return(SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName));
        }
Ejemplo n.º 3
0
        private IList <Token> GenerateTokens(PrivateMessage privateMessage)
        {
            var tokens = new List <Token>();

            _messageTokenProvider.AddStoreTokens(tokens);
            _messageTokenProvider.AddPrivateMessageTokens(tokens, privateMessage);
            return(tokens);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a private message notification
        /// </summary>
        /// <param name="privateMessage">Private message</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public virtual IList <int> SendPrivateMessageNotification(PrivateMessage privateMessage, int languageId)
        {
            if (privateMessage == null)
            {
                throw new ArgumentNullException(nameof(privateMessage));
            }

            var store = _storeService.GetStoreById(privateMessage.StoreId) ?? _storeContext.CurrentStore;

            var messageTemplates = GetActiveMessageTemplates(MessageTemplateSystemNames.PrivateMessageNotification, store.Id);

            if (!messageTemplates.Any())
            {
                return(new List <int>());
            }

            //tokens
            var commonTokens = new List <Token>();

            _messageTokenProvider.AddPrivateMessageTokens(commonTokens, privateMessage);
            _messageTokenProvider.AddCustomerTokens(commonTokens, privateMessage.ToCustomer);

            return(messageTemplates.Select(messageTemplate =>
            {
                //email account
                var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId);

                var tokens = new List <Token>(commonTokens);
                _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount);

                //event notification
                _eventPublisher.MessageTokensAdded(messageTemplate, tokens);

                var toEmail = privateMessage.ToCustomer.Email;
                var toName = _customerService.GetCustomerFullName(privateMessage.ToCustomer);

                return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName);
            }).ToList());
        }