コード例 #1
0
ファイル: BeerVotesController.cs プロジェクト: ahansb/BeerApp
        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
ファイル: BeerVotesController.cs プロジェクト: ahansb/BeerApp
        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
ファイル: BeerVotesService.cs プロジェクト: ahansb/BeerApp
 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();
 }