コード例 #1
0
        internal void Vote(string debate_id, string voteCasted, string userVoting)
        {
            Vote vote = new DatabaseAccess.Vote();

            vote.debate_id     = int.Parse(debate_id);
            vote.user_username = userVoting;
            if (voteCasted == "pro")
            {
                vote.vote_pro = true;
            }
            else
            {
                vote.vote_pro = false;
            }

            try
            {
                Vote debateVote = _voteRepository.GetDebateVote(int.Parse(debate_id), userVoting);
                if (debateVote.vote_pro == vote.vote_pro)
                {
                    _voteRepository.Delete(debateVote.vote_id);
                }
                else
                {
                    debateVote.vote_pro = vote.vote_pro;
                    _voteRepository.Update(debateVote);
                }
            }
            catch (VoteException vex)
            {
                if (vex.Message == "333")
                {
                    _voteRepository.Add(vote);
                }
            }
        }