public ActionResult Apply(int contentId, string returnUrl) { var content = _contentManager.Get(contentId); if (content == null || !content.Has <FavoritePart>() || !content.As <FavoritePart>().ShowVoter) { return(this.RedirectLocal(returnUrl, "~/")); } var currentUser = _orchardServices.WorkContext.CurrentUser; if (currentUser == null) { return(this.RedirectLocal(returnUrl, "~/")); } var currentVote = _votingService.Get(vote => vote.Username == currentUser.UserName && vote.ContentItemRecord == content.Record && vote.Dimension == Constants.Dimension).FirstOrDefault(); if (currentVote != null) { _votingService.RemoveVote(currentVote); } else { _votingService.Vote(content, currentUser.UserName, _httpContextAccessor.Current().Request.UserHostAddress, 1, Constants.Dimension); } return(this.RedirectLocal(returnUrl, "~/")); }
public ActionResult Delete(int reviewId, string returnUrl) { var review = _reviewRepository.Get(reviewId); if (review == null) { _orchardServices.Notifier.Error(T("Review was not found.")); return(this.RedirectLocal(returnUrl, "~/")); } VoteRecord voteRecord = _votingService.Get(review.VoteRecordId); if (voteRecord == null) { _orchardServices.Notifier.Error(T("Rating was not found.")); return(this.RedirectLocal(returnUrl, "~/")); } if (voteRecord.Username != _orchardServices.WorkContext.CurrentUser.UserName) { _orchardServices.Notifier.Error(T("You are not authorized to delete this Review.")); return(this.RedirectLocal(returnUrl, "~/")); } _reviewRepository.Delete(review); _votingService.RemoveVote(voteRecord); // I need to evict the content item from the cache because in case of authenticated caching, the review list doesn't get to be refreshed. _cacheService.RemoveByTag(review.ContentItemRecordId.ToString()); _orchardServices.Notifier.Information(T("Your Review has been deleted.")); return(this.RedirectLocal(returnUrl, "~/")); }
public ActionResult Delete(int reviewId, string returnUrl) { var review = _reviewRepository.Get(reviewId); if (review == null) { _orchardServices.Notifier.Error(T("Review was not found.")); return(this.RedirectLocal(returnUrl, "~/")); } VoteRecord voteRecord = _votingService.Get(review.VoteRecordId); if (voteRecord == null) { _orchardServices.Notifier.Error(T("Rating was not found.")); return(this.RedirectLocal(returnUrl, "~/")); } if (voteRecord.Username != _orchardServices.WorkContext.CurrentUser.UserName) { _orchardServices.Notifier.Error(T("You are not authorized to delete this Review.")); return(this.RedirectLocal(returnUrl, "~/")); } _reviewRepository.Delete(review); _votingService.RemoveVote(voteRecord); _orchardServices.Notifier.Information(T("Your Review has been deleted.")); return(this.RedirectLocal(returnUrl, "~/")); }
private void ClearRating(VoteRecord currentVote) { if (currentVote != null) { _votingService.RemoveVote(currentVote); foreach (var reviewRecord in _reviewRecordRepository.Fetch(rr => rr.VoteRecordId == currentVote.Id)) { _reviewRecordRepository.Delete(reviewRecord); } } }
private void ClearRating(VoteRecord currentVote) { if (currentVote != null) { _votingService.RemoveVote(currentVote); foreach (var reviewRecord in _reviewRecordRepository.Fetch(rr => rr.VoteRecordId == currentVote.Id)) { _reviewRecordRepository.Delete(reviewRecord); // I need to evict the content item from the cache because in case of authenticated caching, the review list doesn't get to be refreshed. _cacheService.RemoveByTag(currentVote.ContentItemRecord.Id.ToString()); } } }
public void RegisterUserVote(IUser user, ContentItem contentItem, int rating) { var currentVote = GetUserVote(user, contentItem); if (currentVote != null && (currentVote.Value + rating == 0)) { _votingService.RemoveVote(currentVote); } else { if (currentVote != null) { _votingService.ChangeVote(currentVote, rating); } else { _votingService.Vote(contentItem, user.UserName, _httpContextAccessor.Current().Request.UserHostAddress, rating, Constants.Voting.RatingConstant); } } }