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);
        }
Exemplo n.º 2
0
        protected override DriverResult Display(UserViewPart part, string displayType, dynamic shapeHelper)
        {
            var resultRecord = _votingService.GetResult(part.ContentItem.Id, "sum", Constants.Dimension);

            part.TotalViews = resultRecord == null ? 0 : (int)resultRecord.Value;

            return(Combined(ContentShape("Parts_UserView_Summary", () => shapeHelper.Parts_UserView_Summary(TotalViews: part.TotalViews)),
                            ContentShape("Parts_UserView_SummaryAdmin", () => shapeHelper.Parts_UserView_SummaryAdmin(TotalViews: part.TotalViews))));
        }
Exemplo n.º 3
0
        public double GetResult(ContentItem contentItem)
        {
            var result = _votingService.GetResult(contentItem.Id, "sum", Constants.Voting.RatingConstant);

            if (result == null)
            {
                return(0D);
            }
            return(result.Value);
        }
Exemplo n.º 4
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);
        }