Example #1
0
        //edit comment
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(RedirectToAction("AccessDenied", "Security", new { pageUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request) }));
            }

            var comment = _productCommentService.GetProductCommentById(id);

            if (comment == null || comment.Deleted)
            {
                //No comment found with the specified id
                return(RedirectToAction("List"));
            }

            var product = _productService.GetProductById(comment.ProductId);

            var model = new ProductCommentModel()
            {
                Id            = comment.Id,
                CommentText   = comment.CommentText,
                IsApproved    = comment.IsApproved,
                ReplyText     = comment.ReplyText,
                ProductName   = product.GetLocalized(t => t.Name),
                ProductSeName = product.GetSeName()
            };

            return(View("~/Plugins/Resanehlab.ProductComments/Views/Admin/Edit.cshtml", model));
        }
Example #2
0
        public ActionResult Edit(ProductCommentModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(RedirectToAction("AccessDenied", "Security", new { pageUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request) }));
            }

            var comment = _productCommentService.GetProductCommentById(model.Id);

            if (comment == null || comment.Deleted)
            {
                //No comment found with the specified id
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                comment.ReplyText  = model.ReplyText;
                comment.IsApproved = model.IsApproved;
                comment.Visited    = true;

                _productCommentService.UpdateProductComment(comment);

                SuccessNotification(_localizationService.GetResource("Admin.Plugin.ResanehlabProductComments.Comments.Updated"));

                if (continueEditing)
                {
                    return(RedirectToAction("Edit", new { id = comment.Id }));
                }
                return(RedirectToAction("List"));
            }

            return(View("~/Plugins/Resanehlab.ProductComments/Views/Admin/Edit.cshtml", model));
        }
Example #3
0
        //edit comment
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(new HttpUnauthorizedResult());
            }

            var comment = _productCommentService.GetProductCommentById(id);

            if (comment == null || comment.Deleted)
            {
                //No comment found with the specified id
                return(RedirectToAction("List"));
            }

            var product = _productService.GetProductById(comment.ProductId);
            var model   = new ProductCommentModel()
            {
                Id            = comment.Id,
                CommentText   = comment.CommentText,
                IsApproved    = comment.IsApproved,
                ReplyText     = comment.ReplyText,
                ProductName   = product.GetLocalized(t => t.Name),
                ProductSeName = product.GetSeName()
            };

            return(View("~/Plugins/Resanehlab.ProductComments/Views/Admin/Edit.cshtml", model));
        }
Example #4
0
        public HttpResponseMessage Post(ProductCommentModel model)
        {
            var detail = _orderDetailService.GetOrderDetailById(model.ProductDetailsId);

            if (detail == null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "无法找到评价商品所在订单")));
            }
            detail.Status = EnumOrderDetailStatus.已评价;

            var entity = new ProductCommentEntity
            {
                Product     = _productService.GetProductById(model.ProductId),
                Member      = _memberService.GetMemberByUserId(_workContext.CurrentUser.Id),
                AddTime     = DateTime.Now,
                Content     = model.Content,
                Stars       = model.Stars,
                OrderDetail = _orderDetailService.GetOrderDetailById(model.ProductDetailsId)
            };

            using (var tran = new TransactionScope())
            {
                if (_productCommentService.Create(entity).Id > 0 && _orderDetailService.Update(detail).Id > 0)
                {
                    tran.Complete();
                    return(PageHelper.toJson(PageHelper.ReturnValue(true, "添加成功!")));
                }
            }

            return(PageHelper.toJson(PageHelper.ReturnValue(false, "添加失败!")));
        }
Example #5
0
        public ActionResult ProductCommentList(DataSourceRequest command, ProductCommentListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(RedirectToAction("AccessDenied", "Security", new { pageUrl = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Request) }));
            }

            bool?overrideIsApproved = null;

            if (model.SearchIsApprovedId == 1)
            {
                overrideIsApproved = true;
            }
            else if (model.SearchIsApprovedId == 2)
            {
                overrideIsApproved = false;
            }

            bool?overrideVisited = null;

            if (model.SearchVisitedId == 1)
            {
                overrideVisited = true;
            }
            else if (model.SearchVisitedId == 2)
            {
                overrideVisited = false;
            }

            var comments = _productCommentService.GetAllProductComments(isApproved: overrideIsApproved,
                                                                        visited: overrideVisited,
                                                                        storeId: _storeContext.CurrentStore.Id,
                                                                        commentText: model.SearchCommentText,
                                                                        productName: model.SearchProductName,
                                                                        pageIndex: command.Page - 1,
                                                                        pageSize: command.PageSize);

            var gridModel = new DataSourceResult();

            gridModel.Data = comments.Select(x =>
            {
                var p = _productService.GetProductById(x.ProductId);
                var productCommentModel = new ProductCommentModel()
                {
                    Id            = x.Id,
                    CommentText   = x.CommentText,
                    CreatedOnStr  = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc).ToString("g"),
                    IsApproved    = x.IsApproved,
                    ReplyText     = x.ReplyText,
                    Visited       = x.Visited,
                    ProductName   = p.GetLocalized(t => t.Name),
                    ProductSeName = p.GetSeName()
                };
                return(productCommentModel);
            });
            gridModel.Total = comments.TotalCount;

            return(Json(gridModel));
        }
Example #6
0
        public HttpResponseMessage Get(int id)
        {
            var entity = _productCommentService.GetProductCommentById(id);
            var model  = new ProductCommentModel
            {
                Id        = entity.Id,
                ProductId = entity.Product.Id,
                //AddUser = entity.AddUser,
                AddTime = entity.AddTime,
                Content = entity.Content,
                Stars   = entity.Stars,
            };

            return(PageHelper.toJson(model));
        }
Example #7
0
        /// <summary>
        /// 修改评论
        /// </summary>
        /// <param name="model">评论实体</param>
        /// <returns>Bool</returns>
        public HttpResponseMessage Put(ProductCommentModel model)
        {
            var entity = _productCommentService.GetProductCommentById(model.Id);

            if (entity == null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "没有该评论!")));
            }
            entity.Product = _productService.GetProductById(model.Id);
            //entity.AddUser = model.AddUser;
            entity.AddTime = model.AddTime;
            entity.Content = model.Content;
            entity.Stars   = model.Stars;
            if (_productCommentService.Update(entity) != null)
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(true, "修改成功!")));
            }
            return(PageHelper.toJson(PageHelper.ReturnValue(false, "修改失败!")));
        }