Example #1
0
        private void SaveVote(int movieId, int userId, bool like)
        {
            var vote = GetMovieVoteForUser(movieId, userId);

            if (vote == No.Vote)
            {
                var newVote = new Vote(userId, movieId);
                if (like)
                {
                    newVote.LikeMovie();
                }
                else
                {
                    newVote.HateMovie();
                }

                _voteRepository.AddVote(newVote);
            }
            else
            {
                if (like)
                {
                    vote.LikeMovie();
                }
                else
                {
                    vote.HateMovie();
                }
                _voteRepository.UpdateVote(vote);
            }

            var voteResult = GetMovieVotes(movieId);

            if (voteResult == No.Votes)
            {
                var newVoteResult = new VoteResult(movieId);
                if (like)
                {
                    newVoteResult.LikeMovie();
                }
                else
                {
                    newVoteResult.HateMovie();
                }
                _voteRepository.AddVoteResult(newVoteResult);
            }
            else
            {
                if (like)
                {
                    voteResult.LikeMovie();
                }
                else
                {
                    voteResult.HateMovie();
                }
                _voteRepository.UpdateVoteResult(voteResult);
            }
        }