Esempio n. 1
0
        public ActionResult SaveReview(ReviewFormSaveReviewViewModel viewModel)
        {
            var product = _productRepository.SingleOrDefault(x => x.Guid.ToString() == viewModel.ProductGuid);

            var catalogGroup   = _catalogContext.CurrentCatalogGroup;
            var catalogGroupV2 = ProductCatalogGroup.FirstOrDefault(x => x.Guid == catalogGroup.Guid);

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

            var name           = viewModel.Name;
            var email          = viewModel.Email;
            var rating         = viewModel.Rating * 20;
            var reviewHeadline = viewModel.Title;
            var reviewText     = viewModel.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();

            review.ProductCatalogGroup = catalogGroupV2;
            review.ProductReviewStatus = _productReviewStatusRepository.SingleOrDefault(s => s.Name == "New");
            review.CreatedOn           = DateTime.Now;
            review.CreatedBy           = "System";
            review.Product             = product;
            review.Customer            = basket.PurchaseOrder.Customer;
            review.Rating         = rating;
            review.ReviewHeadline = reviewHeadline;
            review.ReviewText     = reviewText;
            review.Ip             = request.UserHostName;

            product.AddProductReview(review);

            _productReviewPipeline.Execute(review);


            return(Json(new { Rating = review.Rating, ReviewHeadline = review.ReviewHeadline, CreatedBy = review.CreatedBy, CreatedOn = review.CreatedOn.ToString("MMM dd, yyyy"), CreatedOnForMeta = review.CreatedOn.ToString("yyyy-MM-dd"), Comments = review.ReviewText }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index(ProductReviewViewModel formReview)
        {
            var product   = CatalogLibrary.GetProduct(formReview.ProductSku);
            var productV2 = Product.FirstOrDefault(x => x.Guid == product.Guid);

            var catalogGroup   = CatalogContext.CurrentCatalogGroup;
            var catalogGroupV2 = ProductCatalogGroup.FirstOrDefault(x => x.Guid == catalogGroup.Guid);

            var request = System.Web.HttpContext.Current.Request;
            var basket  = 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 = catalogGroupV2,
                ProductReviewStatus = ProductReviewStatus.SingleOrDefault(s => s.Name == "New"),
                CreatedOn           = DateTime.Now,
                CreatedBy           = "System",
                Product             = productV2,
                Customer            = basket.PurchaseOrder.Customer,
                Rating         = rating,
                ReviewHeadline = reviewHeadline,
                ReviewText     = reviewText,
                Ip             = request.UserHostName
            };

            productV2.AddProductReview(review);

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

            //TODO: Add Category to this url.
            return(Redirect(UrlService.GetUrl(CatalogContext.CurrentCatalog, product)));
        }