public static bool AddVoteV2(Guid leagueId, long pollId, List<VotingQuestionClass> questions, Guid memberId)
        {

            var dc = new ManagementContext();
            try
            {
                var voting = dc.VotingV2.Where(x => x.LeagueOwner.LeagueId == leagueId && x.IsDeleted == false && x.VotingId == pollId).FirstOrDefault();

                foreach (var question in voting.Questions)
                {
                    try
                    {
                        //gets the local question.
                        var q = questions.Where(x => x.QuestionId == question.QuestionId).FirstOrDefault();
                        //checks for a vote within the DB.
                        var vote = question.Votes.Where(x => x.Member.MemberId == memberId).FirstOrDefault();
                        if (vote == null)
                        {//adds the vote if not in the DB.
                            Votes v = new Votes();
                            var tempVote = q.Votes.FirstOrDefault();
                            foreach (var answerId in tempVote.AnswerIds)
                            {
                                var a = question.Answers.Where(x => x.AnswerId == answerId).FirstOrDefault();
                                VotesAnswersSelected sel = new VotesAnswersSelected();
                                sel.AnswerSelected = a;
                                sel.Vote = v;
                                v.AnswersSelected.Add(sel);
                            }
                            v.HasVoted = true;
                            v.Member = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
                            v.OtherText = tempVote.OtherText;
                            question.Votes.Add(v);
                        }
                        else
                        {
                            var tempVote = q.Votes.FirstOrDefault();

                            var pastAnswers = vote.AnswersSelected.ToList();
                            //remove answers from past set that weren't selected this time.
                            for (int i = 0; i < pastAnswers.Count; i++)
                            {
                                if (!tempVote.AnswerIds.Contains(pastAnswers[i].AnswerSelected.AnswerId))
                                {
                                    vote.AnswersSelected.Remove(pastAnswers[i]);
                                }
                            }
                            //add new answers selected
                            foreach (var answerId in tempVote.AnswerIds)
                            {
                                var existingAnswer = pastAnswers.Where(x => x.AnswerSelected.AnswerId == answerId).FirstOrDefault();
                                if (existingAnswer == null)
                                {
                                    var a = question.Answers.Where(x => x.AnswerId == answerId).FirstOrDefault();
                                    VotesAnswersSelected sel = new VotesAnswersSelected();
                                    sel.AnswerSelected = a;
                                    sel.Vote = vote;
                                    vote.AnswersSelected.Add(sel);
                                }
                            }
                            vote.OtherText = tempVote.OtherText;
                        }
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }
                int c = dc.SaveChanges();
                return c > 0;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
        //public static VotingClass GetPoll(Guid leagueId, long pollId)
        //{

        //    var dc = new ManagementContext();
        //    try
        //    {
        //        VotingClass v = new VotingClass();
        //        var mem = RDN.Library.Classes.Account.User.GetMemberId();
        //        var voting = dc.Voting.Where(x => x.LeagueOwner.LeagueId == leagueId && x.IsDeleted == false && x.VotingId == pollId).FirstOrDefault();
        //        v.IsPublic = voting.IsPublic;
        //        v.IsDeleted = voting.IsDeleted;
        //        v.IsClosed = voting.IsClosed;
        //        v.Version = 1;
        //        v.Question = voting.Question;
        //        v.Description = voting.Description;
        //        v.VotingId = voting.VotingId;
        //        v.IsPollAnonymous = voting.IsPollAnonymous;
        //        v.LeagueId = leagueId.ToString().Replace("-", "");
        //        //making due for old polls.
        //        if (voting.Created < new DateTime(2013, 10, 26))
        //        {
        //            v.MembersDidntVote = MemberCache.GetLeagueMembers(mem, leagueId);
        //            for (int vo = 0; vo < voting.Votes.Count; vo++)
        //            {
        //                try
        //                {
        //                    VotesClass vc = new VotesClass();
        //                    vc.IPAddress = voting.Votes[vo].IPAddress;
        //                    vc.OtherText = voting.Votes[vo].OtherText;
        //                    vc.Created = voting.Votes[vo].Created;
        //                    if (voting.Votes[vo].AnswerSelected != null)
        //                        vc.AnswerId = voting.Votes[vo].AnswerSelected.AnswerId;
        //                    if (voting.Votes[vo].Member != null)
        //                    {
        //                        vc.MemberId = voting.Votes[vo].Member.MemberId;
        //                        vc.DerbyName = voting.Votes[vo].Member.DerbyName;
        //                        vc.UserId = voting.Votes[vo].Member.AspNetUserId;
        //                    }
        //                    vc.VoteId = voting.Votes[vo].VoteId;
        //                    v.Votes.Add(vc);
        //                    v.MembersDidntVote.Remove(v.MembersDidntVote.Where(x => x.MemberId == vc.MemberId).FirstOrDefault());
        //                }
        //                catch (Exception exception)
        //                {
        //                    ErrorDatabaseManager.AddException(exception, exception.GetType());
        //                }
        //            }
        //        }
        //        else
        //        {
        //            v.MembersDidntVote = new List<Account.Classes.MemberDisplay>();
        //            for (int vo = 0; vo < voting.Votes.Count; vo++)
        //            {
        //                try
        //                {
        //                    VotesClass vc = new VotesClass();
        //                    vc.HasVoted = voting.Votes[vo].HasVoted;
        //                    vc.IPAddress = voting.Votes[vo].IPAddress;
        //                    vc.OtherText = voting.Votes[vo].OtherText;
        //                    vc.Created = voting.Votes[vo].Created;
        //                    if (voting.Votes[vo].AnswerSelected != null)
        //                        vc.AnswerId = voting.Votes[vo].AnswerSelected.AnswerId;
        //                    if (voting.Votes[vo].Member != null)
        //                    {
        //                        vc.MemberId = voting.Votes[vo].Member.MemberId;
        //                        vc.DerbyName = voting.Votes[vo].Member.DerbyName;
        //                    }
        //                    vc.VoteId = voting.Votes[vo].VoteId;
        //                    if (vc.HasVoted)
        //                    {
        //                        v.Votes.Add(vc);
        //                    }
        //                    else
        //                        v.MembersDidntVote.Add(new Account.Classes.MemberDisplay() { MemberId = vc.MemberId, DerbyName = vc.DerbyName });
        //                }
        //                catch (Exception exception)
        //                {
        //                    ErrorDatabaseManager.AddException(exception, exception.GetType());
        //                }
        //            }
        //        }
        //        for (int vo = 0; vo < voting.Answers.Count; vo++)
        //        {
        //            try
        //            {
        //                VotingAnswersClass vc = new VotingAnswersClass();
        //                vc.Answer = voting.Answers[vo].Answer;
        //                vc.AnswerId = voting.Answers[vo].AnswerId;
        //                v.Answers.Add(vc);
        //            }
        //            catch (Exception exception)
        //            {
        //                ErrorDatabaseManager.AddException(exception, exception.GetType());
        //            }
        //        }

        //        return v;
        //    }
        //    catch (Exception exception)
        //    {
        //        ErrorDatabaseManager.AddException(exception, exception.GetType());
        //    }
        //    return null;
        //}
        public static bool AddVote(Guid leagueId, long pollId, Guid memberId, long answerId, string otherText)
        {

            var dc = new ManagementContext();
            try
            {
                var voting = dc.Voting.Include("Votes").Include("Answers").Where(x => x.LeagueOwner.LeagueId == leagueId && x.IsDeleted == false && x.VotingId == pollId).FirstOrDefault();
                if (voting == null)
                    return false;
                var vote = voting.Votes.Where(x => x.Member.MemberId == memberId).FirstOrDefault();
                if (vote == null)
                {
                    Votes v = new Votes();
                    v.AnswerSelected = voting.Answers.Where(x => x.AnswerId == answerId).FirstOrDefault();
                    v.Member = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
                    v.OtherText = otherText;
                    v.HasVoted = true;
                    voting.Votes.Add(v);

                }
                else
                {
                    vote.OtherText = otherText;
                    vote.AnswerSelected = voting.Answers.Where(x => x.AnswerId == answerId).FirstOrDefault();
                    vote.HasVoted = true;
                }
                int c = dc.SaveChanges();
                return c > 0;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }