示例#1
0
        public ActionResult Vote(int beerId, int voteType)
        {
            if (voteType > 1)
            {
                voteType = 1;
            }

            if (voteType < -1)
            {
                voteType = -1;
            }

            var userId = this.User.Identity.GetUserId();
            var vote   = this.votes.GetByUserAndBeerId(userId, beerId);

            if (vote == null)
            {
                vote = new BeerVote
                {
                    VoterId = userId,
                    BeerId  = beerId,
                    Type    = (VoteType)voteType
                };
                this.votes.AddVote(vote);
            }
            else
            {
                if (vote.Type == VoteType.Neutral)
                {
                    vote.Type = (VoteType)voteType;
                }
                else if (vote.Type != (VoteType)voteType)
                {
                    vote.Type = VoteType.Neutral;
                }

                this.votes.SaveVoteChanges();
            }

            var beerVoteCount = this.votes.CountVotes(beerId);

            return(this.Json(new { Count = beerVoteCount }));
        }
示例#2
0
        public ActionResult Vote(int beerId, int voteType)
        {
            if (voteType > 1)
            {
                voteType = 1;
            }

            if (voteType < -1)
            {
                voteType = -1;
            }

            var userId = this.User.Identity.GetUserId();
            var vote = this.votes.GetByUserAndBeerId(userId, beerId);

            if (vote == null)
            {
                vote = new BeerVote
                {
                    VoterId = userId,
                    BeerId = beerId,
                    Type = (VoteType) voteType
                };
                this.votes.AddVote(vote);
            }
            else
            {
                if (vote.Type == VoteType.Neutral)
                {
                    vote.Type = (VoteType) voteType;
                }
                else if (vote.Type != (VoteType)voteType)
                {
                    vote.Type = VoteType.Neutral;
                }

                this.votes.SaveVoteChanges();
            }

            var beerVoteCount = this.votes.CountVotes(beerId);

            return this.Json(new { Count = beerVoteCount });
        }
示例#3
0
 public void AddVote(BeerVote beerVote)
 {
     this.beerVotes.Add(beerVote);
     this.beerVotes.Save();
 }
示例#4
0
 public void AddVote(BeerVote beerVote)
 {
     this.beerVotes.Add(beerVote);
     this.beerVotes.Save();
 }