Ejemplo n.º 1
0
        public ActionResult Review(ProductReviewModel model)
        {
            if (ModelState.IsValid)
            {
                var product = _productService.GetById(model.ProductId);
                model.Product = product;
                try
                {
                    var review =
                        _productReviewService.Get(x => model.ProductId == x.ProductId && (x.EmailAddress == model.EmailAddress || x.UserName == model.UserName));
                    if (review == null)
                    {
                        var entity = model.ToEntity();
                        _productReviewService.Add(entity);
                        this.SuccessNotification("Thank you for your review. We will email you once it has been approved.");
                    }
                    else
                    {
                        this.ErrorNotification(review.EmailAddress == model.EmailAddress
                                                   ? "The email address entered is already in use. Please use another email address"
                                                   : "The username entered is already in use. Please use another username");
                        return PartialView(model);
                    }
                }
                catch (Exception)
                {

                    this.ErrorNotification("An error has occurred while submitting your review. Please try again later.");
                }
            }
            int productId = model.ProductId;
            model = new ProductReviewModel { Product = _productService.GetById(productId) };
            return PartialView(model);
        }
Ejemplo n.º 2
0
 public ActionResult Review(int id)
 {
     var model = new ProductReviewModel
                     {
                         Product = _productService.GetById(id),
                         ProductId = id
                     };
     return PartialView(model);
 }