Exemplo n.º 1
0
        //edit
        public virtual ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageArticleReviews))
            {
                return(AccessDeniedView());
            }

            var articleReview = _articleService.GetArticleReviewById(id);

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

            //a contributor should have access only to his articles
            if (_workContext.CurrentContributor != null && articleReview.Article.ContributorId != _workContext.CurrentContributor.Id)
            {
                return(RedirectToAction("List"));
            }

            var model = new ArticleReviewModel();

            PrepareArticleReviewModel(model, articleReview, false, false);
            return(View(model));
        }
Exemplo n.º 2
0
        public virtual ActionResult List(DataSourceRequest command, ArticleReviewListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageArticleReviews))
            {
                return(AccessDeniedKendoGridJson());
            }

            //a contributor should have access only to his articles
            var contributorId = 0;

            if (_workContext.CurrentContributor != null)
            {
                contributorId = _workContext.CurrentContributor.Id;
            }

            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 articleReviews = _articleService.GetAllArticleReviews(0, approved,
                                                                      createdOnFromValue, createdToFromValue, model.SearchText,
                                                                      model.SearchStoreId, model.SearchArticleId, contributorId,
                                                                      command.Page - 1, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data = articleReviews.Select(x =>
                {
                    var m = new ArticleReviewModel();
                    PrepareArticleReviewModel(m, x, false, true);
                    return(m);
                }),
                Total = articleReviews.TotalCount
            };

            return(Json(gridModel));
        }
Exemplo n.º 3
0
        protected virtual void PrepareArticleReviewModel(ArticleReviewModel model,
                                                         ArticleReview articleReview, bool excludeProperties, bool formatReviewAndReplyText)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

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

            model.Id          = articleReview.Id;
            model.StoreName   = articleReview.Store.Name;
            model.ArticleId   = articleReview.ArticleId;
            model.ArticleName = articleReview.Article.Name;
            model.CustomerId  = articleReview.CustomerId;
            var customer = articleReview.Customer;

            model.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
            model.Rating       = articleReview.Rating;
            model.CreatedOn    = _dateTimeHelper.ConvertToUserTime(articleReview.CreatedOnUtc, DateTimeKind.Utc);
            if (!excludeProperties)
            {
                model.Title = articleReview.Title;
                if (formatReviewAndReplyText)
                {
                    model.ReviewText = Core.Html.HtmlHelper.FormatText(articleReview.ReviewText, false, true, false, false, false, false);
                    model.ReplyText  = Core.Html.HtmlHelper.FormatText(articleReview.ReplyText, false, true, false, false, false, false);
                }
                else
                {
                    model.ReviewText = articleReview.ReviewText;
                    model.ReplyText  = articleReview.ReplyText;
                }
                model.IsApproved = articleReview.IsApproved;
            }

            //a contributor should have access only to his articles
            model.IsLoggedInAsContributor = _workContext.CurrentContributor != null;
        }
Exemplo n.º 4
0
        public virtual ActionResult Edit(ArticleReviewModel model, bool continueEditing)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageArticleReviews))
            {
                return(AccessDeniedView());
            }

            var articleReview = _articleService.GetArticleReviewById(model.Id);

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

            //a contributor should have access only to his articles
            if (_workContext.CurrentContributor != null && articleReview.Article.ContributorId != _workContext.CurrentContributor.Id)
            {
                return(RedirectToAction("List"));
            }

            if (ModelState.IsValid)
            {
                var isLoggedInAsContributor = _workContext.CurrentContributor != null;

                var previousIsApproved = articleReview.IsApproved;
                //contributor can edit "Reply text" only
                if (!isLoggedInAsContributor)
                {
                    articleReview.Title      = model.Title;
                    articleReview.ReviewText = model.ReviewText;
                    articleReview.IsApproved = model.IsApproved;
                }

                articleReview.ReplyText = model.ReplyText;
                _articleService.UpdateArticle(articleReview.Article);

                //activity log
                _customerActivityService.InsertActivity("EditArticleReview", _localizationService.GetResource("ActivityLog.EditArticleReview"), articleReview.Id);

                //contributor can edit "Reply text" only
                if (!isLoggedInAsContributor)
                {
                    //update article totals
                    _articleService.UpdateArticleReviewTotals(articleReview.Article);

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

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

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


            //If we got this far, something failed, redisplay form
            PrepareArticleReviewModel(model, articleReview, true, false);
            return(View(model));
        }