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 })); }
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 }); }
public void AddVote(BeerVote beerVote) { this.beerVotes.Add(beerVote); this.beerVotes.Save(); }