public Vote AddVoteToIdeation(int value, string userId, string email, int ideationId) { _unitOfWorkManager.StartUnitOfWork(); bool isUserVote = !userId.IsNullOrEmpty(); bool isEmailVote = !email.IsNullOrEmpty(); Vote vote = null; if (isUserVote) { vote = _userManager.GetVoteForIdeation(ideationId, userId); } else if (isEmailVote) { vote = _userManager.GetEmailVoteForIdeation(ideationId, 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.AddVoteToIdeation(vote, ideationId); _unitOfWorkManager.EndUnitOfWork(); if (vote == null) { throw new Exception("Something went wrong while creating the vote."); } return(vote); }