public ActionResult Vote(VoteForReviewViewModel vfrvm)
        {
            var currentUserId = this.User.Identity.GetUserId();

            if (this._service.UserHasAlreadyVotedForReview(currentUserId, vfrvm.Id))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotAcceptable));
            }
            this._service.CastUserVote(currentUserId, vfrvm);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Example #2
0
        public void CastUserVote(string currentUserId, VoteForReviewViewModel vote)
        {
            var customer = this.Context.Customers.First(c => c.UserId == currentUserId);
            var review   = this.Context.Reviews.Find(vote.Id);

            if (vote.Vote == "up")
            {
                review.Useful++;
            }
            else
            {
                review.Useless++;
            }
            customer.VotedFor.Add(review);
            this.Context.SaveChanges();
        }