public Vote AddVoteToComment(int value, string userId, string email, int commentId) { _unitOfWorkManager.StartUnitOfWork(); bool isUserVote = !userId.IsNullOrEmpty(); bool isEmailVote = !email.IsNullOrEmpty(); Vote vote = null; if (isUserVote) { vote = _userManager.GetVoteForComment(commentId, userId); } else if (isEmailVote) { vote = _userManager.GetEmailVoteForComment(commentId, email); } if (vote == null) { if (isUserVote) { vote = _userManager.AddVoteToUser(value, userId); } else if (isEmailVote) { vote = _userManager.AddVoteWithEmail(value, email); } else { vote = _userManager.AddAnonymousVote(value); } } else { vote = _userManager.ChangeVoteValue(vote.VoteId, value); } _ideationManager.AddVoteToComment(vote, commentId); _unitOfWorkManager.EndUnitOfWork(); if (vote == null) { throw new Exception("Something went wrong while creating the vote."); } return(vote); }