public ActionResult SubmitReview(AddReviewSubmitModel reviewModel) { var model = ResolveModel(); var parameters = new System.Collections.Generic.Dictionary <string, object>(); string message; parameters.Add("submitModel", model); if (!model.CanProcessRequest(parameters, out message)) { return(this.Json(new OperationStatusDTO() { Status = "failed", Message = message }, JsonRequestBehavior.AllowGet)); } var viewModel = model.Add(reviewModel); return(Json(viewModel, JsonRequestBehavior.AllowGet)); }
public virtual AddReviewDTO Add(AddReviewSubmitModel viewModel) { Ucommerce.EntitiesV2.Product product; if (viewModel.ProductId.HasValue) { product = Ucommerce.EntitiesV2.Product.Get(viewModel.ProductId.Value); } else { product = Ucommerce.EntitiesV2.Product.FirstOrDefault(p => p.Guid == CatalogContext.CurrentProduct.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 Ucommerce.EntitiesV2.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(); Ucommerce.EntitiesV2.ProductCatalogGroup catalogGroup; if (viewModel.CatalogGroupId.HasValue) { catalogGroup = Ucommerce.EntitiesV2.ProductCatalogGroup.Get(viewModel.CatalogGroupId.Value); } else { catalogGroup = Ucommerce.EntitiesV2.ProductCatalogGroup.FirstOrDefault(x => x.Guid == CatalogContext.CurrentCatalogGroup.Guid); } var review = new Ucommerce.EntitiesV2.ProductReview { ProductCatalogGroup = catalogGroup, ProductReviewStatus = ProductReviewStatusRepository.SingleOrDefault(s => s.ProductReviewStatusId == (int)ProductReviewStatusCode.New), CreatedOn = DateTime.Now, CreatedBy = "System", Product = product, Customer = basket.PurchaseOrder.Customer, Rating = rating, ReviewHeadline = reviewHeadline, ReviewText = reviewText, Ip = request.UserHostName }; product.AddProductReview(review); ProductReviewPipeline.Execute(review); var reviewDTO = new AddReviewDTO { Rating = rating, Comments = reviewText, ReviewHeadline = reviewHeadline, CreatedBy = review.CreatedBy, CreatedOn = review.CreatedOn.ToString("MMM dd, yyyy"), CreatedOnForMeta = review.CreatedOn.ToString("yyyy-MM-dd") }; product.AddProductReview(review); ProductReviewPipeline.Execute(review); return(reviewDTO); }