Exemplo n.º 1
0
        /// <summary>
        /// Updates the product review
        /// </summary>
        /// <param name="productReview">Product review</param>
        public void UpdateProductReview(ProductReview productReview)
        {
            if (productReview == null)
                throw new ArgumentNullException("productReview");

            productReview.IPAddress = CommonHelper.EnsureNotNull(productReview.IPAddress);
            productReview.IPAddress = CommonHelper.EnsureMaximumLength(productReview.IPAddress, 100);
            productReview.Title = CommonHelper.EnsureNotNull(productReview.Title);
            productReview.Title = CommonHelper.EnsureMaximumLength(productReview.Title, 1000);
            productReview.ReviewText = CommonHelper.EnsureNotNull(productReview.ReviewText);

            if (!_context.IsAttached(productReview))
                _context.ProductReviews.Attach(productReview);

            _context.SaveChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a product review notification message to a store owner
        /// </summary>
        /// <param name="productReview">Product review</param>
        /// <param name="languageId">Message language identifier</param>
        /// <returns>Queued email identifier</returns>
        public int SendProductReviewNotificationMessage(ProductReview productReview,
            int languageId)
        {
            if (productReview == null)
                throw new ArgumentNullException("productReview");

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

            var emailAccount = localizedMessageTemplate.EmailAccount;

            string subject = ReplaceMessageTemplateTokens(productReview, localizedMessageTemplate.Subject);
            string body = ReplaceMessageTemplateTokens(productReview, 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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Replaces a message template tokens
        /// </summary>
        /// <param name="productReview">Product review</param>
        /// <param name="template">Template</param>
        /// <returns>New template</returns>
        private string ReplaceMessageTemplateTokens(ProductReview productReview,
            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("ProductReview.ProductName", HttpUtility.HtmlEncode(productReview.Product.Name));

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

            return template;
        }
Exemplo n.º 4
0
        private static ProductReview DBMapping(DBProductReview dbItem)
        {
            if (dbItem == null)
                return null;

            ProductReview item = new ProductReview();
            item.ProductReviewID = dbItem.ProductReviewID;
            item.ProductID = dbItem.ProductID;
            item.CustomerID = dbItem.CustomerID;
            item.Title = dbItem.Title;
            item.ReviewText = dbItem.ReviewText;
            item.Rating = dbItem.Rating;
            item.HelpfulYesTotal = dbItem.HelpfulYesTotal;
            item.HelpfulNoTotal = dbItem.HelpfulNoTotal;
            item.IsApproved = dbItem.IsApproved;
            item.CreatedOn = dbItem.CreatedOn;

            return item;
        }