public ActionResult Index(ProductReviewViewModel formReview)
        {
            var product  = SiteContext.Current.CatalogContext.CurrentProduct;
            var category = SiteContext.Current.CatalogContext.CurrentCategory;

            var request = System.Web.HttpContext.Current.Request;
            var basket  = SiteContext.Current.OrderContext.GetBasket();

            if (request.Form.AllKeys.All(x => x != "review-product"))
            {
                return(RedirectToAction("Index"));
            }

            var name           = formReview.Name;
            var email          = formReview.Email;
            var rating         = Convert.ToInt32(formReview.Rating) * 20;
            var reviewHeadline = formReview.Title;
            var reviewText     = formReview.Comments;

            if (basket.PurchaseOrder.Customer == null)
            {
                basket.PurchaseOrder.Customer = new Customer()
                {
                    FirstName = name, LastName = String.Empty, EmailAddress = email
                };
            }
            else
            {
                basket.PurchaseOrder.Customer.FirstName = name;
                if (basket.PurchaseOrder.Customer.LastName == null)
                {
                    basket.PurchaseOrder.Customer.LastName = String.Empty;
                }
                basket.PurchaseOrder.Customer.EmailAddress = email;
            }

            basket.PurchaseOrder.Customer.Save();

            var review = new ProductReview()
            {
                ProductCatalogGroup = SiteContext.Current.CatalogContext.CurrentCatalogGroup,
                ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"),
                CreatedOn           = DateTime.Now,
                CreatedBy           = "System",
                Product             = product,
                Customer            = basket.PurchaseOrder.Customer,
                Rating         = rating,
                ReviewHeadline = reviewHeadline,
                ReviewText     = reviewText,
                Ip             = request.UserHostName
            };

            product.AddProductReview(review);

            PipelineFactory.Create <ProductReview>("ProductReview").Execute(review);

            return(Redirect(CatalogLibrary.GetNiceUrlForProduct(product, category)));
        }
        public void LeaveReview(Product product, string name, string email, string ratingKey, string reviewHeadline, string reviewText)
        {
            var request = HttpContext.Current.Request;
            var basket  = SiteContext.Current.OrderContext.GetBasket();

            if (request.Form.AllKeys.All(x => x != "review-product"))
            {
                return;
            }

            var rating = Convert.ToInt32(request.Form[ratingKey]) * 20;

            if (basket.PurchaseOrder.Customer == null)
            {
                basket.PurchaseOrder.Customer = new Customer()
                {
                    FirstName = name, LastName = String.Empty, EmailAddress = email
                };
            }
            else
            {
                basket.PurchaseOrder.Customer.FirstName = name;
                if (basket.PurchaseOrder.Customer.LastName == null)
                {
                    basket.PurchaseOrder.Customer.LastName = String.Empty;
                }
                basket.PurchaseOrder.Customer.EmailAddress = email;
            }

            basket.PurchaseOrder.Customer.Save();

            var review = new ProductReview()
            {
                ProductCatalogGroup = SiteContext.Current.CatalogContext.CurrentCatalogGroup,
                ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"),
                CreatedOn           = DateTime.Now,
                CreatedBy           = "System",
                Product             = product,
                Customer            = basket.PurchaseOrder.Customer,
                Rating         = rating,
                ReviewHeadline = reviewHeadline,
                ReviewText     = reviewText,
                Ip             = request.UserHostName
            };

            product.AddProductReview(review);

            PipelineFactory.Create <ProductReview>("ProductReview").Execute(review);
            Response.Redirect(Request.RawUrl);
        }
示例#3
0
        public IHttpActionResult PutProductReview([FromBody] ProductReviewDTO model)
        {
            var product = Product.FirstOrDefault(x => x.Sku == model.Sku && x.VariantSku == null);
            var request = System.Web.HttpContext.Current.Request;
            var basket  = TransactionLibrary.HasBasket() ? TransactionLibrary.GetBasket(false) : null;

            if (basket != null)
            {
                if (basket.PurchaseOrder.Customer == null)
                {
                    basket.PurchaseOrder.Customer = new Customer()
                    {
                        FirstName = model.Name, LastName = string.Empty, EmailAddress = model.Email
                    };
                    basket.Save();
                }
            }

            var review = new ProductReview()
            {
                ProductCatalogGroup = SiteContext.Current.CatalogContext.CurrentCatalogGroup,
                ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"),
                CreatedOn           = DateTime.Now,
                CreatedBy           = model.Name,
                Product             = product,
                Customer            = basket?.PurchaseOrder?.Customer,
                Rating         = model.Rating,
                ReviewHeadline = model.Title,
                ReviewText     = model.Comments,
                Ip             = request.UserHostName,
            };

            product.AddProductReview(review);

            PipelineFactory.Create <ProductReview>("ProductReview").Execute(review);

            return(Ok());
        }