Пример #1
0
        /// <summary>
        /// Sends a blog comment notification message to a store owner
        /// </summary>
        /// <param name="blogComment">Blog comment</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendBlogCommentNotificationMessage(BlogComment blogComment, int languageId)
        {
            if (blogComment == null)
                throw new ArgumentNullException("blogComment");

            string templateName = "Blog.BlogComment";
            var localizedMessageTemplate = this.GetLocalizedMessageTemplate(templateName, languageId);
            if(localizedMessageTemplate == null || !localizedMessageTemplate.IsActive)
                return 0;

            var emailAccount = localizedMessageTemplate.EmailAccount;

            string subject = ReplaceMessageTemplateTokens(blogComment, localizedMessageTemplate.Subject);
            string body = ReplaceMessageTemplateTokens(blogComment, localizedMessageTemplate.Body);
            string bcc = localizedMessageTemplate.BccEmailAddresses;
            var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var to = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var queuedEmail = InsertQueuedEmail(5, from, to, string.Empty, bcc, subject, body,
                DateTime.UtcNow, 0, null, emailAccount.EmailAccountId);
            return queuedEmail.QueuedEmailId;
        }
Пример #2
0
        private static BlogComment DBMapping(DBBlogComment dbItem)
        {
            if (dbItem == null)
                return null;

            BlogComment item = new BlogComment();
            item.BlogCommentID = dbItem.BlogCommentID;
            item.BlogPostID = dbItem.BlogPostID;
            item.CustomerID = dbItem.CustomerID;
            item.CommentText = dbItem.CommentText;
            item.CreatedOn = dbItem.CreatedOn;

            return item;
        }
Пример #3
0
        /// <summary>
        /// Replaces a message template tokens
        /// </summary>
        /// <param name="blogComment">Blog comment</param>
        /// <param name="template">Template</param>
        /// <returns>New template</returns>
        private string ReplaceMessageTemplateTokens(BlogComment blogComment,
            string template)
        {
            var tokens = new NameValueCollection();
            tokens.Add("Store.Name", IoC.Resolve<ISettingManager>().StoreName);
            tokens.Add("Store.URL", IoC.Resolve<ISettingManager>().StoreUrl);
            tokens.Add("Store.Email", this.DefaultEmailAccount.Email);

            tokens.Add("BlogComment.BlogPostTitle", HttpUtility.HtmlEncode(blogComment.BlogPost.BlogPostTitle));

            foreach (string token in tokens.Keys)
            {
                template = Replace(template, String.Format(@"%{0}%", token), tokens[token]);
            }

            return template;
        }
Пример #4
0
        /// <summary>
        /// Updates the blog comment
        /// </summary>
        /// <param name="blogComment">Blog comment</param>
        public void UpdateBlogComment(BlogComment blogComment)
        {
            if (blogComment == null)
                throw new ArgumentNullException("blogComment");

            blogComment.IPAddress = CommonHelper.EnsureNotNull(blogComment.IPAddress);
            blogComment.IPAddress = CommonHelper.EnsureMaximumLength(blogComment.IPAddress, 100);
            blogComment.CommentText = CommonHelper.EnsureNotNull(blogComment.CommentText);

            if (!_context.IsAttached(blogComment))
                _context.BlogComments.Attach(blogComment);

            _context.SaveChanges();
        }