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, "~/"));
        }
        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, "~/"));
        }
Пример #4
0
 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);
         }
     }
 }
Пример #5
0
 private void Vote(ContentItem content, IUser currentUser, int rating, VoteRecord currentVote)
 {
     if (currentVote != null)
     {
         _votingService.ChangeVote(currentVote, rating);
     }
     else
     {
         _votingService.Vote(content, currentUser.UserName, HttpContext.Request.UserHostAddress, rating);
     }
 }
Пример #6
0
        public void RemoveVote(VoteRecord vote)
        {
            foreach (var function in _functions)
            {
                _calculator.Calculate(new DeleteCalculus {
                    Dimension = vote.Dimension, ContentId = vote.ContentItemRecord.Id, Vote = vote.Value, FunctionName = function.Name
                });
            }

            _voteRepository.Delete(vote);
            _eventHandler.VoteRemoved(vote);
        }
 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());
         }
     }
 }
        private void Vote(ContentItem content, IUser currentUser, int rating, VoteRecord currentVote)
        {
            if (currentVote != null)
            {
                _votingService.ChangeVote(currentVote, rating);
            }
            else
            {
                _votingService.Vote(content, currentUser.UserName, HttpContext.Request.UserHostAddress, rating);
            }

            // 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(content.Id.ToString());
        }
Пример #9
0
        public void ChangeVote(VoteRecord vote, double value)
        {
            var previousValue = value;

            foreach (var function in _functions)
            {
                _calculator.Calculate(new UpdateCalculus {
                    Dimension = vote.Dimension, ContentId = vote.ContentItemRecord.Id, PreviousVote = vote.Value, Vote = value, FunctionName = function.Name
                });
            }

            vote.CreatedUtc = _clock.UtcNow;
            vote.Value      = value;

            _eventHandler.VoteChanged(vote, previousValue);
        }
Пример #10
0
        public async Task <IActionResult> Submit(VoteInput input)
        {
            var token = HttpContext.Request.Headers["Authorization"].Last().Split(" ").Last();
            var roles = new List <string>()
            {
                "User"
            };

            var handler = new JwtSecurityTokenHandler();
            var sub     = handler.ReadJwtToken(token).Payload.Sub;

            if (RoleService.CheckRoles(token, roles, _userManager))
            {
                var vote = VoteInputConverter.Convert(input);

                var detailsRepo     = new UserDetailsRepository();
                var voteRecordsRepo = new VoteRecordRepository();

                var detailsId = detailsRepo.GetByUserId(sub).Id;
                var surveyId  = vote.SurveyId;

                if (voteRecordsRepo.GetAll().Count(x => x.UserDetailsId == detailsId && x.SurveyId == surveyId) == 0)
                {
                    _repository.Add(vote);



                    var record = new VoteRecord(surveyId, detailsId);
                    voteRecordsRepo.Add(record);

                    return(CreatedAtAction("Submit", vote));
                }

                return(BadRequest("You already voted"));
            }
            else
            {
                return(BadRequest("Only Users can vote."));
            }
        }
Пример #11
0
        public void Vote(Orchard.ContentManagement.ContentItem contentItem, string userName, string hostname, double value, string dimension = null)
        {
            var vote = new VoteRecord {
                Dimension         = dimension,
                ContentItemRecord = contentItem.Record,
                ContentType       = contentItem.ContentType,
                CreatedUtc        = _clock.UtcNow,
                Hostname          = hostname,
                Username          = userName,
                Value             = value
            };

            _voteRepository.Create(vote);

            foreach (var function in _functions)
            {
                _calculator.Calculate(new CreateCalculus {
                    Dimension = dimension, ContentId = contentItem.Id, FunctionName = function.Name, Vote = value
                });
            }

            _eventHandler.Voted(vote);
        }