Ejemplo n.º 1
0
        public ActionResult Review(ArticleReview articleReview)
        {
            if (ModelState.IsValid)
            {
                Article currentArticle = db.Articles.SingleOrDefault(a => a.Id == articleReview.articleModel.Id);

                if (articleReview.reviewModel.Accepted)
                {
                    currentArticle.StateId = 2; // Set as Reviewed
                }
                else
                {
                    currentArticle.StateId = 3; // Set as Finished
                }
                Review newReview = new Review();
                newReview.Comment      = articleReview.reviewModel.Comment;
                newReview.Accepted     = articleReview.reviewModel.Accepted;
                newReview.UserId       = User.Identity.GetUserId();
                newReview.DateReviewed = DateTime.Now;

                db.Reviews.Add(newReview);

                currentArticle.ReviewId = newReview.Id;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(articleReview));
        }
Ejemplo n.º 2
0
        public ActionResult EditorialReview(ArticleReview articleReview)
        {
            if (ModelState.IsValid)
            {
                Article currentArticle = db.Articles.SingleOrDefault(a => a.Id == articleReview.articleModel.Id);
                Review  currentReview  = db.Reviews.SingleOrDefault(r => r.Id == articleReview.reviewModel.Id);

                currentArticle.StateId = 3;

                currentReview.DateEdited = DateTime.Now;
                currentReview.Comment    = articleReview.reviewModel.Comment;
                currentReview.Accepted   = articleReview.reviewModel.Accepted;
                currentReview.UserId     = User.Identity.GetUserId();

                if (currentReview.Accepted && articleReview.articleModel.DatePublished != null)
                {
                    Publish publish = new Publish();
                    publish.ArticleId   = currentArticle.Id;
                    publish.PublishDate = (DateTime)articleReview.articleModel.DatePublished;
                    db.Publishes.Add(publish);
                }
                else if (currentReview.Accepted && articleReview.articleModel.DatePublished == null)
                {
                    ViewBag.Message = "'Date Published' is required for Accepted articles.";
                    var tmpBind = (ArticleReview)TempData.Peek("tmpArticleReview");
                    return(View(tmpBind));
                }

                db.SaveChanges();
                return(RedirectToAction("PendingEditorial"));
            }

            return(View(articleReview));
        }
        public ActionResult Review(ArticleReview reviewArticle)
        {
            if (ModelState.IsValid)
            {
                // We have a  valid model, let's grab the article from our ViewModel
                Article article = db.Articles.SingleOrDefault(a => a.ArticleId == reviewArticle.articleModel.ArticleId);

                if (reviewArticle.reviewModel.Accepted)
                {
                    article.ArticleStateId = 2; // Set as Reviewed
                }
                else
                {
                    article.ArticleStateId = 3; // Set as Finished
                }
                // Create a new review to add to DB
                Review review = new Review();

                // Pull data from View Model
                review.Text         = reviewArticle.reviewModel.Text;
                review.Accepted     = reviewArticle.reviewModel.Accepted;
                review.ReviewUserId = User.Identity.GetUserId(); // Use current logged in user's ID
                review.DateReviewed = DateTime.Now;

                db.Reviews.Add(review);                    // Add new review

                article.ArticleReviewId = review.ReviewId; // Add the new review id created to the article to save.

                db.SaveChanges();                          // Commit all changes
                return(RedirectToAction("PendingReview")); // Pull back new list
            }

            // Redo process since model was invalid.
            return(View(reviewArticle));
        }
Ejemplo n.º 4
0
        public ActionResult EditorialReview(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("BadRequest"));
            }

            // Create article
            Article article = db.Articles.Find(id);
            Review  review  = db.Articles.Find(id).Review;

            if (article == null || review == null)
            {
                return(RedirectToAction("Missing"));
            }

            // Using the View Model created
            var articleReview = new ArticleReview
            {
                articleModel = article,
                reviewModel  = review
            };

            TempData["tmpArticleReview"] = articleReview;

            return(View(articleReview));
        }
        public ActionResult EditorialReview(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            // Create article
            Article article = db.Articles.Find(id);
            Review  review  = db.Articles.Find(id).Review;

            if (article == null || review == null)
            {
                return(HttpNotFound());
            }

            // Using the View Model created
            var articleReview = new ArticleReview
            {
                articleModel = article, // Use found article attached
                reviewModel  = review   // Insert a new empty Review
            };

            return(View(articleReview));
        }
Ejemplo n.º 6
0
        public ActionResult SaveReview(int id, string content)
        {
            var articleReview = new ArticleReview
            {
                ArticleId     = id,
                CreatedTime   = DateTime.Now,
                ReviewContent = content
            };

            _articleRepository.InsertReview(articleReview);
            _articleRepository.Save();
            return(Json(new { success = true }));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取文章评论信息
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string GetArticleReviewlist(HttpContext context)
        {
            string           id        = context.Request["articleid"];
            int              pageIndex = int.Parse(context.Request["pageindex"]);
            int              pageSize  = int.Parse(context.Request["pagesize"]);
            ArticleReviewApi apiResult = new ArticleReviewApi();
            StringBuilder    sbWhere   = new StringBuilder();

            sbWhere.AppendFormat(" ReviewID={0}", id);
            apiResult.totalcount = bll.GetCount <ReplyReviewInfo>(sbWhere.ToString());
            List <ReplyReviewInfo> data       = bll.GetLit <BLLJIMP.Model.ReplyReviewInfo>(pageSize, pageIndex, sbWhere.ToString(), " AutoId desc");
            List <ArticleReview>   jsonResult = new List <ArticleReview>();

            foreach (var item in data)
            {
                ArticleReview review = new ArticleReview();
                //目标评论内容
                if (item.PraentId > 0)
                {
                    var targetReply = bll.Get <ReplyReviewInfo>(string.Format("AutoId={0}", item.PraentId)); if (targetReply != null)
                    {
                        review.reply = new ArticleReplyReview();
                        review.reply.reviewcontent = targetReply.ReplyContent;
                        review.reply.nickname      = targetReply.UserName;
                    }
                }

                //目标评论内容
                var userInfo = bllUser.GetUserInfo(item.UserId);
                if (userInfo != null)
                {
                    review.headimg = userInfo.WXHeadimgurlLocal;
                }
                review.id            = item.AutoId;
                review.nickname      = item.UserName;
                review.time          = bll.GetTimeStamp(item.InsertDate);
                review.reviewcontent = item.ReplyContent;
                if ((bll.IsLogin) && (item.UserId.Equals(currentUserInfo.UserID)))
                {
                    review.deleteflag = true;
                }


                jsonResult.Add(review);
            }
            apiResult.list = jsonResult;
            return(Common.JSONHelper.ObjectToJson(apiResult));
        }
        public ActionResult EditorialReview(ArticleReview reviewArticle)
        {
            if (ModelState.IsValid)
            {
                // We have a  valid model, let's grab the article from our ViewModel
                Article article = db.Articles.SingleOrDefault(a => a.ArticleId == reviewArticle.articleModel.ArticleId);
                Review  review  = db.Reviews.SingleOrDefault(r => r.ReviewId == reviewArticle.reviewModel.ReviewId);

                // Update database items from review model.
                article.Title = reviewArticle.articleModel.Title;
                article.Text  = reviewArticle.articleModel.Text;
                review.Text   = reviewArticle.reviewModel.Text;

                // Go up another state to finished
                article.ArticleStateId = 3;
                // Set The Date Edited for the Review
                review.DateEdited = DateTime.Now;

                // See post editorial review if we should publish article
                if (reviewArticle.reviewModel.Accepted && reviewArticle.articleModel.DatePublished != null)
                {
                    review.Accepted       = reviewArticle.reviewModel.Accepted;
                    article.DatePublished = reviewArticle.articleModel.DatePublished;
                    Publish publish = new Publish();
                    publish.ArticleId   = article.ArticleId;
                    publish.PublishDate = (DateTime)article.DatePublished;
                    db.Publishes.Add(publish);
                }
                // Accepted but no DatePublished included, need to improve.
                else if (reviewArticle.reviewModel.Accepted && reviewArticle.articleModel.DatePublished == null)
                {
                    ViewBag.Message = "If article is accepted, Date Published must be filled in.";

                    reviewArticle.articleModel.AspNetUser  = article.AspNetUser;
                    reviewArticle.articleModel.DateCreated = article.DateCreated;
                    return(View(reviewArticle));
                }

                db.SaveChanges();                             // Commit all changes
                return(RedirectToAction("PendingEditorial")); // Pull back new list
            }

            // Redo process since model was invalid.
            return(View(reviewArticle));
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        public ActionResult Review(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("BadRequest"));
            }
            Article article = db.Articles.Find(id);

            if (article == null)
            {
                return(RedirectToAction("Missing"));
            }

            var articleReview = new ArticleReview
            {
                articleModel = article,
                reviewModel  = new Review()
            };

            return(View(articleReview));
        }
Ejemplo n.º 11
0
 public void InsertReview(ArticleReview articleReview)
 {
     //_context.ArticleReviews.Add(articleReview);
 }
Ejemplo n.º 12
0
 public ArticleReviewApprovedEvent(ArticleReview articleReview)
 {
     this.ArticleReview = articleReview;
 }
Ejemplo n.º 13
0
        public ActionResult SetReviewHelpfulness(int articleReviewId, bool washelpful)
        {
            var article = _articleService.GetArticleById(articleReviewId);

            if (article == null || article.Deleted || article.StatusFormat != StatusFormat.Norma || !article.AllowUserReviews)
            {
                return(HttpNotFound());
            }

            var articleReview = article.ArticleReviews.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc).FirstOrDefault() as ArticleReview;

            if (articleReview == null)
            {
                bool isApproved = !_catalogSettings.ArticleReviewsMustBeApproved;
                var  user       = _services.WorkContext.CurrentUser;
                //添加新的评论赞
                articleReview = new ArticleReview()
                {
                    ArticleId       = article.Id,
                    UserId          = user.Id,
                    IpAddress       = _services.WebHelper.GetCurrentIpAddress(),
                    Rating          = 0,
                    HelpfulYesTotal = 0,
                    HelpfulNoTotal  = 0,
                    IsApproved      = isApproved,
                    CreatedOnUtc    = DateTime.UtcNow,
                    ModifiedOnUtc   = DateTime.UtcNow,
                };
                _userContentService.InsertUserContent(articleReview);
            }

            if (_services.WorkContext.CurrentUser.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle)
            {
                return(Json(new
                {
                    Success = false,
                    Result = T("Reviews.Helpfulness.OnlyRegistered").Text,
                    TotalYes = articleReview.HelpfulYesTotal,
                    TotalNo = articleReview.HelpfulNoTotal
                }));
            }

            //users aren't allowed to vote for their own reviews
            if (articleReview.UserId == _services.WorkContext.CurrentUser.Id)
            {
                return(Json(new
                {
                    Success = false,
                    Result = T("Reviews.Helpfulness.YourOwnReview").Text,
                    TotalYes = articleReview.HelpfulYesTotal,
                    TotalNo = articleReview.HelpfulNoTotal
                }));
            }

            //delete previous helpfulness
            var oldPrh = (from prh in articleReview.ArticleReviewHelpfulnessEntries
                          where prh.UserId == _services.WorkContext.CurrentUser.Id
                          select prh).FirstOrDefault();

            if (oldPrh != null)
            {
                _userContentService.DeleteUserContent(oldPrh);
            }

            //insert new helpfulness
            var newPrh = new ArticleReviewHelpfulness()
            {
                ArticleReviewId = articleReview.Id,
                UserId          = _services.WorkContext.CurrentUser.Id,
                IpAddress       = _services.WebHelper.GetCurrentIpAddress(),
                WasHelpful      = washelpful,
                IsApproved      = true, //always approved
                CreatedOnUtc    = DateTime.UtcNow,
                ModifiedOnUtc   = DateTime.UtcNow,
            };

            _userContentService.InsertUserContent(newPrh);

            //new totals
            int helpfulYesTotal = (from prh in articleReview.ArticleReviewHelpfulnessEntries
                                   where prh.WasHelpful
                                   select prh).Count();
            int helpfulNoTotal = (from prh in articleReview.ArticleReviewHelpfulnessEntries
                                  where !prh.WasHelpful
                                  select prh).Count();

            articleReview.HelpfulYesTotal = helpfulYesTotal;
            articleReview.HelpfulNoTotal  = helpfulNoTotal;
            _userContentService.UpdateUserContent(articleReview);

            return(Json(new
            {
                Success = true,
                Result = T("Reviews.Helpfulness.SuccessfullyVoted").Text,
                TotalYes = articleReview.HelpfulYesTotal,
                TotalNo = articleReview.HelpfulNoTotal
            }));
        }
Ejemplo n.º 14
0
        // [CaptchaValidator]
        public ActionResult ReviewsAdd(int id, ArticleReviewsModel model, bool captchaValid)
        {
            var article = _articleService.GetArticleById(id);

            if (article == null || article.Deleted || article.StatusFormat != StatusFormat.Norma || !article.AllowUserReviews)
            {
                return(HttpNotFound());
            }

            if (_services.WorkContext.CurrentUser.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle)
            {
                ModelState.AddModelError("", T("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (ModelState.IsValid)
            {
                //save review
                int rating = model.AddArticleReview.Rating;
                if (rating < 1 || rating > 5)
                {
                    rating = _catalogSettings.DefaultArticleRatingValue;
                }

                bool isApproved = !_catalogSettings.ArticleReviewsMustBeApproved;
                var  user       = _services.WorkContext.CurrentUser;

                var articleReview = new ArticleReview()
                {
                    ArticleId = article.Id,
                    UserId    = user.Id,
                    IpAddress = _services.WebHelper.GetCurrentIpAddress(),

                    Rating          = rating,
                    HelpfulYesTotal = 0,
                    HelpfulNoTotal  = 0,
                    IsApproved      = isApproved,
                    CreatedOnUtc    = DateTime.UtcNow,
                    ModifiedOnUtc   = DateTime.UtcNow,
                };
                _userContentService.InsertUserContent(articleReview);

                //update article totals
                _articleService.UpdateArticleReviewTotals(article);

                //activity log
                _services.UserActivity.InsertActivity("PublicStore.AddArticleReview", T("ActivityLog.PublicStore.AddArticleReview"), article.Title);

                //if (isApproved)
                //    _userService.RewardPointsForArticleReview(user, article, true);

                _helper.PrepareArticleReviewsModel(model, article);

                model.AddArticleReview.SuccessfullyAdded = true;
                if (!isApproved)
                {
                    model.AddArticleReview.Result = T("Reviews.SeeAfterApproving");
                }
                else
                {
                    model.AddArticleReview.Result = T("Reviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            _helper.PrepareArticleReviewsModel(model, article);
            return(View(model));
        }
Ejemplo n.º 15
0
        public virtual ActionResult ArticleReviewsAdd(int articleId, ArticleReviewsModel model, bool captchaValid)
        {
            var article = _articleService.GetArticleById(articleId);

            if (article == null || article.Deleted || !article.Published || !article.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnArticleReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ArticleReviewPossibleOnlyAfterPurchasing &&
                !_subscriptionService.SearchSubscriptions(customerId: _workContext.CurrentCustomer.Id, articleId: articleId, osIds: new List <int> {
                (int)SubscriptionStatus.Complete
            }).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ArticleReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                //save review
                int rating = model.AddArticleReview.Rating;
                if (rating < 1 || rating > 5)
                {
                    rating = _catalogSettings.DefaultArticleRatingValue;
                }
                bool isApproved = !_catalogSettings.ArticleReviewsMustBeApproved;

                var articleReview = new ArticleReview
                {
                    ArticleId       = article.Id,
                    CustomerId      = _workContext.CurrentCustomer.Id,
                    Title           = model.AddArticleReview.Title,
                    ReviewText      = model.AddArticleReview.ReviewText,
                    Rating          = rating,
                    HelpfulYesTotal = 0,
                    HelpfulNoTotal  = 0,
                    IsApproved      = isApproved,
                    CreatedOnUtc    = DateTime.UtcNow,
                    StoreId         = _storeContext.CurrentStore.Id,
                };
                article.ArticleReviews.Add(articleReview);
                _articleService.UpdateArticle(article);

                //update article totals
                _articleService.UpdateArticleReviewTotals(article);

                //notify store owner
                if (_catalogSettings.NotifyStoreOwnerAboutNewArticleReviews)
                {
                    _workflowMessageService.SendArticleReviewNotificationMessage(articleReview, _localizationSettings.DefaultAdminLanguageId);
                }

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddArticleReview", _localizationService.GetResource("ActivityLog.PublicStore.AddArticleReview"), article.Name);

                //raise event
                if (articleReview.IsApproved)
                {
                    _eventPublisher.Publish(new ArticleReviewApprovedEvent(articleReview));
                }

                model = _articleModelFactory.PrepareArticleReviewsModel(model, article);
                model.AddArticleReview.Title      = null;
                model.AddArticleReview.ReviewText = null;

                model.AddArticleReview.SuccessfullyAdded = true;
                if (!isApproved)
                {
                    model.AddArticleReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
                }
                else
                {
                    model.AddArticleReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = _articleModelFactory.PrepareArticleReviewsModel(model, article);
            return(View(model));
        }