Ejemplo n.º 1
0
 public VoteRecord GetUserVote(IUser user, ContentItem contentItem)
 {
     return(_votingService.Get(vote =>
                               vote.Username == user.UserName &&
                               vote.ContentItemRecord == contentItem.Record &&
                               vote.Dimension == Constants.Voting.RatingConstant).FirstOrDefault());
 }
        private ReviewsPart BuildStars(ReviewsPart part, string displayType)
        {
            part.Rating.CurrentVotingResult = _votingService.GetResult(part.ContentItem.Id, "average") ?? new ResultRecord();

            // get the user's vote
            var currentUser = _orchardServices.WorkContext.CurrentUser;

            if (currentUser != null)
            {
                var userRating = _votingService.Get(vote => vote.Username == currentUser.UserName && vote.ContentItemRecord == part.ContentItem.Record).FirstOrDefault();
                if (userRating != null)
                {
                    part.Rating.UserRating = userRating.Value;
                }
                else
                {
                    part.Rating.UserRating = 0;
                }
            }

            if (displayType == "Detail" || displayType == "Details")
            {
                BuildReviews(part, part.Rating.CurrentVotingResult, currentUser);
            }

            return(part);
        }
        public ActionResult Create(int contentId, string comment, string returnUrl)
        {
            IUser currentUser = _orchardServices.WorkContext.CurrentUser;

            VoteRecord userVote = _votingService.Get(v => v.ContentItemRecord.Id == contentId && v.Username == currentUser.UserName).FirstOrDefault();

            if (userVote == null)
            {
                _orchardServices.Notifier.Error(T("In order to submit a review, you must also submit a rating."));
                TempData["Comment"] = comment;
            }
            else if (_reviewRepository.Fetch(r => r.VoteRecordId == userVote.Id).Any())
            {
                _orchardServices.Notifier.Error(T("You have already left a review for this item."));
            }
            else if (string.IsNullOrWhiteSpace(comment))
            {
                _orchardServices.Notifier.Error(T("Please fill out your comment before submitting your review."));
            }
            else if (comment.Length > 1200)
            {
                _orchardServices.Notifier.Error(T("Your comment must be less than 1,200 characters in length."));
                TempData["Comment"] = comment;
            }
            else
            {
                var review = new ReviewRecord {
                    Comment = comment, CreatedUtc = _clock.UtcNow, ContentItemRecordId = contentId, VoteRecordId = userVote.Id
                };
                _reviewRepository.Create(review);
                _orchardServices.Notifier.Information(T("Thank you for submitting your review."));
            }

            return(this.RedirectLocal(returnUrl, "~/"));
        }
Ejemplo n.º 4
0
        public ActionResult Apply(int contentId, int rating, string returnUrl)
        {
            var content = _contentManager.Get(contentId);

            if (content == null)
            {
                return(this.RedirectLocal(returnUrl, "~/"));
            }

            var currentUser = _orchardServices.WorkContext.CurrentUser;

            if (RequestIsInvalid(currentUser, rating)) // invalid and no-op (0)
            {
                return(this.RedirectLocal(returnUrl, "~/"));
            }

            var currentVote = _votingService.Get(vote => vote.Username == currentUser.UserName && vote.ContentItemRecord == content.Record).FirstOrDefault();

            if (rating == -1)
            {
                ClearRating(currentVote);
            }
            else
            {
                Vote(content, currentUser, rating, currentVote);
            }

            return(this.RedirectLocal(returnUrl, "~/"));
        }
Ejemplo n.º 5
0
        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, "~/"));
        }
Ejemplo n.º 6
0
        private FavoritePart BuildVoteUpDown(FavoritePart part)
        {
            var currentUser = _authenticationService.GetAuthenticatedUser();

            if (currentUser != null)
            {
                var resultRecord = _votingService.GetResult(part.ContentItem.Id, "sum", Constants.Dimension);

                part.IsFavorite        = (resultRecord != null && resultRecord.Value > 0.0);
                part.NumberOfFavorites = _votingService.Get(vote => vote.Username == currentUser.UserName && vote.Dimension == Constants.Dimension).Sum(o => o.Value);
            }

            return(part);
        }
Ejemplo n.º 7
0
        private void Vote(string userName, UserViewPart part, UserViewTypePartSettings settings)
        {
            var currentVote = _votingService.Get(vote =>
                                                 vote.ContentItemRecord == part.ContentItem.Record &&
                                                 vote.Username == userName &&
                                                 vote.Dimension == Constants.Dimension).FirstOrDefault();

            if (currentVote != null && settings.AllowMultipleViewsFromSameUserToCount)
            {
                _votingService.ChangeVote(currentVote, (currentVote.Value + 1));
            }
            else if (currentVote == null)
            {
                _votingService.Vote(part.ContentItem, userName, _orchardServices.WorkContext.HttpContext.Request.UserHostAddress, 1, Constants.Dimension);
            }
        }
Ejemplo n.º 8
0
        public async Task <object> Get()
        {
            var voting = await _votingService.Get();

            return(voting.GetState());
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Index()
        {
            var model = await _votingService.Get();

            return(View(model));
        }