コード例 #1
0
        public ActionResult SaveReview(ProductReviewModel model)
        {
            var customer = _customerService.GetCustomerId(model.CustomerId);

            model.CustomerName = customer.NickName;
            return(View());
        }
コード例 #2
0
        public ActionResult List(GridCommand command, ProductReviewListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _customerContentService.GetAllCustomerContent <ProductReview>(0, null,
                                                                                               createdOnFromValue, createdToFromValue);
            var gridModel = new GridModel <ProductReviewModel>
            {
                Data = productReviews.PagedForCommand(command).Select(x =>
                {
                    var m = new ProductReviewModel();
                    PrepareProductReviewModel(m, x, false, true);
                    return(m);
                }),
                Total = productReviews.Count,
            };

            return(new JsonResult
            {
                Data = gridModel
            });
        }
コード例 #3
0
        //edit
        public virtual ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            var productReview = _productService.GetProductReviewById(id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            #region Extensions by QuanNH
            var _storeMappingService = Nop.Core.Infrastructure.EngineContext.Current.Resolve <Nop.Services.Stores.IStoreMappingService>();
            if (!_storeMappingService.TableEdit(productReview.ProductId, "Product"))
            {
                return(RedirectToAction("List"));
            }

            #endregion

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && productReview.Product.VendorId != _workContext.CurrentVendor.Id)
            {
                return(RedirectToAction("List"));
            }

            var model = new ProductReviewModel();
            PrepareProductReviewModel(model, productReview, false, false);
            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> AddReview(ProductReviewModel productReviewModel)
        {
            await _productGraphClient.AddReview(productReviewModel);

            return(RedirectToAction("ProductDetail",
                                    new { productId = productReviewModel.ProductId }));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(ProductReviewModel model, bool continueEditing)
        {
            var productReview = await _productReviewService.GetProductReviewById(model.Id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff() && productReview.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productReview = await _productReviewViewModelService.UpdateProductReview(productReview, model);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated"));
                return(continueEditing ? RedirectToAction("Edit", new { id = productReview.Id, ProductId = productReview.ProductId }) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            await _productReviewViewModelService.PrepareProductReviewModel(model, productReview, true, false);

            return(View(model));
        }
コード例 #6
0
        private void PrepareProductReviewModel(ProductReviewModel model, ProductReview productReview, bool excludeProperties, bool formatReviewText)
        {
            Guard.NotNull(model, nameof(model));
            Guard.NotNull(productReview, nameof(productReview));

            model.Id                   = productReview.Id;
            model.ProductId            = productReview.ProductId;
            model.ProductName          = productReview.Product.Name;
            model.ProductTypeName      = productReview.Product.GetProductTypeLabel(_localizationService);
            model.ProductTypeLabelHint = productReview.Product.ProductTypeLabelHint;
            model.CustomerId           = productReview.CustomerId;
            model.CustomerName         = productReview.Customer.GetDisplayName(T);
            model.IpAddress            = productReview.IpAddress;
            model.Rating               = productReview.Rating;
            model.CreatedOn            = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);

            if (!excludeProperties)
            {
                model.Title      = productReview.Title;
                model.IsApproved = productReview.IsApproved;

                model.ReviewText = formatReviewText
                    ? HtmlUtils.ConvertPlainTextToHtml(productReview.ReviewText.HtmlEncode())
                    : productReview.ReviewText;
            }
        }
コード例 #7
0
        public ActionResult List(GridCommand command, ProductReviewListModel model)
        {
            DateTime?createdFrom = (model.CreatedOnFrom == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdTo = (model.CreatedOnTo == null) ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _customerContentService.GetAllCustomerContent <ProductReview>(
                0,
                null,
                createdFrom,
                createdTo,
                command.Page - 1,
                command.PageSize);

            var gridModel = new GridModel <ProductReviewModel>
            {
                Total = productReviews.TotalCount
            };

            gridModel.Data = productReviews.Select(x =>
            {
                var m = new ProductReviewModel();
                PrepareProductReviewModel(m, x, false, true);
                return(m);
            });

            return(new JsonResult
            {
                Data = gridModel
            });
        }
コード例 #8
0
        public ActionResult Edit(ProductReviewModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            var productReview = _productService.GetProductReviewById(model.Id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productReview.Title      = model.Title;
                productReview.ReviewText = model.ReviewText;
                productReview.IsApproved = model.IsApproved;
                _productService.UpdateProduct(productReview.Product);

                //update product totals
                _productService.UpdateProductReviewTotals(productReview.Product);

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated"));
                return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List"));
            }


            //If we got this far, something failed, redisplay form
            PrepareProductReviewModel(model, productReview, true, false);
            return(View(model));
        }
コード例 #9
0
        public ActionResult Edit(ProductReviewModel model, bool continueEditing)
        {
            var productReview = _customerContentService.GetCustomerContentById(model.Id) as ProductReview;

            if (productReview == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productReview.Title      = model.Title;
                productReview.ReviewText = model.ReviewText;
                productReview.IsApproved = model.IsApproved;
                _customerContentService.UpdateCustomerContent(productReview);

                _productService.UpdateProductReviewTotals(productReview.Product);

                _customerService.RewardPointsForProductReview(productReview.Customer, productReview.Product, productReview.IsApproved);

                NotifySuccess(T("Admin.Catalog.ProductReviews.Updated"));
                return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List"));
            }

            PrepareProductReviewModel(model, productReview, true, false);
            return(View(model));
        }
コード例 #10
0
        public ActionResult List(DataSourceRequest command, ProductReviewListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            bool?approved = null;

            if (model.SearchApprovedId > 0)
            {
                approved = model.SearchApprovedId == 1;
            }

            var productReviews = _productService.GetAllProductReviews(0, approved,
                                                                      createdOnFromValue, createdToFromValue, model.SearchText, model.SearchStoreId, model.SearchProductId, command.Page - 1, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data = productReviews.Select(x =>
                {
                    var m = new ProductReviewModel();
                    PrepareProductReviewModel(m, x, false, true);
                    return(m);
                }),
                Total = productReviews.TotalCount
            };

            return(Json(gridModel));
        }
コード例 #11
0
        public ActionResult Edit(ProductReviewModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog))
            {
                return(AccessDeniedView());
            }

            var productReview = _customerContentService.GetCustomerContentById(model.Id) as ProductReview;

            if (productReview == null)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                productReview.Title      = model.Title;
                productReview.ReviewText = model.ReviewText;
                productReview.IsApproved = model.IsApproved;
                _customerContentService.UpdateCustomerContent(productReview);

                //update product totals
                _productService.UpdateProductReviewTotals(productReview.Product);

                _customerService.RewardPointsForProductReview(productReview.Customer, productReview.Product, productReview.IsApproved);

                NotifySuccess(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated"));
                return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List"));
            }

            //If we got this far, something failed, redisplay form
            PrepareProductReviewModel(model, productReview, true, false);
            return(View(model));
        }
コード例 #12
0
        //edit
        public virtual ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            var productReview = _productService.GetProductReviewById(id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && productReview.Product.VendorId != _workContext.CurrentVendor.Id)
            {
                return(RedirectToAction("List"));
            }

            var model = new ProductReviewModel();

            PrepareProductReviewModel(model, productReview, false, false);
            return(View(model));
        }
コード例 #13
0
        private void PrepareProductReviewModel(ProductReviewModel model,
                                               ProductReview productReview, bool excludeProperties, bool formatReviewText)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (productReview == null)
            {
                throw new ArgumentNullException("productReview");
            }

            model.Id          = productReview.Id;
            model.ProductId   = productReview.ProductId;
            model.ProductName = productReview.Product.Name;
            model.CustomerId  = productReview.CustomerId;
            model.IpAddress   = productReview.IpAddress;
            model.Rating      = productReview.Rating;
            model.CreatedOn   = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);
            if (!excludeProperties)
            {
                model.Title = productReview.Title;
                if (formatReviewText)
                {
                    model.ReviewText = Core.Html.HtmlHelper.FormatText(productReview.ReviewText, false, true, false, false, false, false);
                }
                else
                {
                    model.ReviewText = productReview.ReviewText;
                }
                model.IsApproved = productReview.IsApproved;
            }
        }
コード例 #14
0
        /// <summary>
        /// Prepare product review model
        /// </summary>
        /// <param name="model">Product review model</param>
        /// <param name="productReview">Product review</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Product review model</returns>
        public virtual ProductReviewModel PrepareProductReviewModel(ProductReviewModel model,
                                                                    ProductReview productReview, bool excludeProperties = false)
        {
            if (productReview != null)
            {
                //fill in model values from the entity
                model = model ?? new ProductReviewModel
                {
                    Id          = productReview.Id,
                    StoreName   = productReview.Store.Name,
                    ProductId   = productReview.ProductId,
                    ProductName = productReview.Product.Name,
                    CustomerId  = productReview.CustomerId,
                    Rating      = productReview.Rating
                };

                model.CustomerInfo = productReview.Customer.IsRegistered()
                    ? productReview.Customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
                model.CreatedOn = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);

                if (!excludeProperties)
                {
                    model.Title      = productReview.Title;
                    model.ReviewText = productReview.ReviewText;
                    model.ReplyText  = productReview.ReplyText;
                    model.IsApproved = productReview.IsApproved;
                }
            }

            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            return(model);
        }
コード例 #15
0
        public async Task <IActionResult> Index(ProductReviewModel productReviewModel)
        {
            await _productReviewService.RegisterReview(productReviewModel);

            ViewData["Result"] = $"Product {productReviewModel.Product} with score {productReviewModel.ProductScore} stored";
            //Trying to empty model, but I´m missing some sort of signal to the webpage, to do an update
            productReviewModel.ClearModel();
            return(View(productReviewModel));
        }
コード例 #16
0
        public ActionResult Review(int id)
        {
            var model = new ProductReviewModel
            {
                Product   = _productService.GetById(id),
                ProductId = id
            };

            return(PartialView(model));
        }
コード例 #17
0
        public ActionResult Review(int productId, int orderItemId)
        {
            ProductReviewModel model = new ProductReviewModel();

            model.CustomerId  = this.CustomerId;
            model.ProductId   = productId;
            model.OrderItemId = orderItemId;
            var product = _productService.GetProductById(productId);

            return(View(model));
        }
コード例 #18
0
ファイル: ProductReviewViewModel.cs プロジェクト: pznmc/tp
 public void UpdateReview()
 {
     try
     {
         ProductReviewModel.UpdateReview(UpdatedReview);
         Reviews = new ObservableCollection <ProductReview>(ProductReviewModel.ProductReviews);
     }
     catch (System.Data.SqlClient.SqlException e)
     {
         MessageBox.Show("Aktualizacja recenzji nie powiodło się: " + e.Message, "Błąd edytowania");
     }
 }
コード例 #19
0
ファイル: ProductReviewViewModel.cs プロジェクト: pznmc/tp
 public void RemoveReview()
 {
     try
     {
         ProductReviewModel.DeleteReview(SelectedReview);
         Reviews = new ObservableCollection <ProductReview>(ProductReviewModel.ProductReviews);
         RefreshButtonAvailability();
     }
     catch (System.Data.SqlClient.SqlException e)
     {
         MessageBox.Show("Usunięcie recenzji nie powiodło się: " + e.Message, "Błąd usuwania");
     }
 }
コード例 #20
0
        public void StoreData(ProductReviewModel productReviewModel)
        {
            SqlConnection conn = GetConnection();

            conn.Open();
            String     sql       = @"INSERT INTO productreview (reviewid,name,product,score) VALUES (@reviewId,@name,@product,@score)";
            SqlCommand dbCommand = new SqlCommand(sql, conn);

            dbCommand.Parameters.AddWithValue("@reviewId", productReviewModel.id);
            dbCommand.Parameters.AddWithValue("@name", productReviewModel.Name);
            dbCommand.Parameters.AddWithValue("@product", productReviewModel.Product);
            dbCommand.Parameters.AddWithValue("@score", productReviewModel.ProductScore);
            dbCommand.ExecuteNonQuery();
        }
コード例 #21
0
        //edit
        public IActionResult Edit(string id, [FromServices] IProductService productService)
        {
            var productReview = productService.GetProductReviewById(id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new ProductReviewModel();

            _productReviewViewModelService.PrepareProductReviewModel(model, productReview, false, false);
            return(View(model));
        }
コード例 #22
0
        public ActionResult Edit(int id)
        {
            var productReview = _customerContentService.GetCustomerContentById(id) as ProductReview;

            if (productReview == null)
            {
                return(RedirectToAction("List"));
            }

            var model = new ProductReviewModel();

            PrepareProductReviewModel(model, productReview, false, false);

            return(View(model));
        }
コード例 #23
0
        public async Task CreateProductReview(ProductReviewViewModel obj)
        {
            await _localDbConnection.CreateTableAsync <ProductReviewModel>();

            ProductReviewModel productReviewModel = new ProductReviewModel()
            {
                ProductID   = obj.ProductID,
                FullName    = obj.FullName,
                Email       = obj.Email,
                Location    = obj.Location,
                Description = obj.Description,
                Rating      = obj.Rating
            };
            await _localDbConnection.InsertAsync(productReviewModel);
        }
コード例 #24
0
ファイル: ProductReviewViewModel.cs プロジェクト: pznmc/tp
 public void AddReview()
 {
     try
     {
         ProductReviewModel.AddReview(AddedReview);
         Reviews        = new ObservableCollection <ProductReview>(ProductReviewModel.ProductReviews);
         SelectedReview = Reviews.Last();
         AddedReview    = new ProductReview();
         RefreshButtonAvailability();
     }
     catch (System.Data.SqlClient.SqlException e)
     {
         MessageBox.Show("Dodanie recenzji nie powiodło się: " + e.Message, "Błąd dodawania");
     }
 }
コード例 #25
0
        public ProductReviewViewModel(ProductReviewModel obj)
        {
            ProductID   = obj.ProductID;
            FullName    = obj.FullName;
            Email       = obj.Email;
            Location    = obj.Location;
            Description = obj.Description;
            Rating      = obj.Rating;

            //setRatingStars(obj);
            IsRatingOne   = (Rating >= 1) ? true : false;
            IsRatingTwo   = (Rating >= 2) ? true : false;
            IsRatingThree = (Rating >= 3) ? true : false;
            IsRatingFour  = (Rating >= 4) ? true : false;
            IsRatingFive  = (Rating == 5) ? true : false;
        }
コード例 #26
0
        public ActionResult Edit(ProductReviewModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProductReviews))
            {
                return(AccessDeniedView());
            }

            var productReview = _productService.GetProductReviewById(model.Id);

            if (productReview == null)
            {
                //No product review found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var previousIsApproved = productReview.IsApproved;

                productReview.Title      = model.Title;
                productReview.ReviewText = model.ReviewText;
                productReview.ReplyText  = model.ReplyText;
                productReview.IsApproved = model.IsApproved;
                _productService.UpdateProduct(productReview.Product);

                //activity log
                _customerActivityService.InsertActivity("EditProductReview", _localizationService.GetResource("ActivityLog.EditProductReview"), productReview.Id);

                //update product totals
                _productService.UpdateProductReviewTotals(productReview.Product);

                //raise event (only if it wasn't approved before and is approved now)
                if (!previousIsApproved && productReview.IsApproved)
                {
                    _eventPublisher.Publish(new ProductReviewApprovedEvent(productReview));
                }

                SuccessNotification(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated"));

                return(continueEditing ? RedirectToAction("Edit", new { id = productReview.Id }) : RedirectToAction("List"));
            }


            //If we got this far, something failed, redisplay form
            PrepareProductReviewModel(model, productReview, true, false);
            return(View(model));
        }
コード例 #27
0
        //edit
        public async Task<IActionResult> Edit(string id, [FromServices] IProductService productService)
        {
            var productReview = await productService.GetProductReviewById(id);

            if (productReview == null)
                //No product review found with the specified id
                return RedirectToAction("List");

            if (_workContext.CurrentCustomer.IsStaff() && productReview.StoreId != _workContext.CurrentCustomer.StaffStoreId)
            {
                return RedirectToAction("List");
            }

            var model = new ProductReviewModel();
            await _productReviewViewModelService.PrepareProductReviewModel(model, productReview, false, false);
            return View(model);
        }
コード例 #28
0
        public async Task AddReview(ProductReviewModel review)
        {
            var query = new GraphQLRequest
            {
                Query     = @" 
                mutation($review: reviewInput!)
                {
                    createReview(review: $review)
                    {
                        id
                    }
                }",
                Variables = new { review }
            };
            var response = await _client.PostAsync(query);

            var reviewReturned = response.GetDataFieldAs <ProductReviewModel>("createReview");
        }
コード例 #29
0
        public virtual (IEnumerable <ProductReviewModel> productReviewModels, int totalCount) PrepareProductReviewsModel(ProductReviewListModel model, int pageIndex, int pageSize)
        {
            DateTime?createdOnFromValue = (model.CreatedOnFrom == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?createdToFromValue = (model.CreatedOnTo == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var productReviews = _productService.GetAllProductReviews("", null,
                                                                      createdOnFromValue, createdToFromValue, model.SearchText, model.SearchStoreId, model.SearchProductId);

            return(productReviews.PagedForCommand(pageIndex, pageSize).Select(x =>
            {
                var m = new ProductReviewModel();
                PrepareProductReviewModel(m, x, false, true);
                return m;
            }), productReviews.Count);
        }
コード例 #30
0
        public virtual async Task PrepareProductReviewModel(ProductReviewModel model,
                                                            ProductReview productReview, bool excludeProperties, bool formatReviewText)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            if (productReview == null)
            {
                throw new ArgumentNullException("productReview");
            }
            var product = await _productService.GetProductById(productReview.ProductId);

            var customer = await _customerService.GetCustomerById(productReview.CustomerId);

            var store = await _storeService.GetStoreById(productReview.StoreId);

            model.Id           = productReview.Id;
            model.StoreName    = store != null ? store.Name : "";
            model.ProductId    = productReview.ProductId;
            model.ProductName  = product.Name;
            model.CustomerId   = productReview.CustomerId;
            model.CustomerInfo = customer != null?customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest") : "";

            model.Rating    = productReview.Rating;
            model.CreatedOn = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);
            model.Signature = productReview.Signature;
            if (!excludeProperties)
            {
                model.Title = productReview.Title;
                if (formatReviewText)
                {
                    model.ReviewText = Core.Html.HtmlHelper.FormatText(productReview.ReviewText, false, true, false, false, false, false);
                    model.ReplyText  = Core.Html.HtmlHelper.FormatText(productReview.ReplyText, false, true, false, false, false, false);
                }
                else
                {
                    model.ReviewText = productReview.ReviewText;
                    model.ReplyText  = productReview.ReplyText;
                }
                model.IsApproved = productReview.IsApproved;
            }
        }