public SingleVoteItem GetModel(SingleVote singleVote)
        {
            var item = new SingleVoteItem();

            item.SingleVoteTicketId = singleVote.SingleVoteId;
            if (singleVote.CandidateId != null)
            {
                item.CandidateItem = CandidateBuilder.GetModel(singleVote.Candidate);
            }
            if (singleVote.VoteIssueId != null)
            {
                item.Issue = VoteIssueBuilder.GetModel(singleVote.BallotIssue);
            }
            return(item);
        }
        public PartialViewResult PositionVoteResult(int id)
        {
            // init count
            int count = 0;

            // init model
            List <SingleVote> model = new List <SingleVote>();

            // get all votes
            var allVotes = db.Votes.ToList().Where(x => x.PositionId == id);

            // loop through all votes and init model
            foreach (var item in allVotes)
            {
                // init count
                count++;

                // get user
                var user = db.VoteUsers.Where(x => x.VoterId == item.VoterId).FirstOrDefault();

                // init singlevm
                SingleVote vote = new SingleVote
                {
                    SN         = count,
                    VoterName  = user.FirstName + " " + user.LastName,
                    VoterPhone = user.Phone,
                    VotedFor   = db.VoteUsers.Where(x => x.VoterId == item.CandidateId).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault()
                };

                model.Add(vote);
            }
            ;

            ViewBag.PositionName = db.Position.Where(x => x.Id == id).Select(x => x.Name).FirstOrDefault();

            ViewBag.PositionActive = db.Position.Where(x => x.Id == id).Select(x => x.IsActive).FirstOrDefault();

            return(PartialView("_PositionVoteResult", model));
        }
        public ActionResult VoteResults()
        {
            // init count
            int count = 0;

            // init model
            VoteResult model = new VoteResult();
            //model.Votes = new List<SingleVote>();

            // init candidateScore
            List <CandidateScore> candidateScores = new List <CandidateScore>();

            // get votes
            var votes = db.Votes.ToArray();

            // get candidates
            var allCandidates = User.GetAllCandidates();

            // init candidate scores
            model.CandidateScores = allCandidates.Select(x => new CandidateScore
            {
                Id         = x.VoterId,
                Name       = x.FirstName + " " + x.LastName,
                VoteCount  = 0,
                PositionId = x.PositionId
            }).ToList();

            // init all position ids
            model.Positions = User.GetAllPositions();

            // loop through votes and get each voter details
            foreach (var item in votes)
            {
                // init count
                count++;

                // get user
                var user = db.VoteUsers.Where(x => x.VoterId == item.VoterId).FirstOrDefault();

                if (model.CandidateScores.Any(x => x.Id == item.CandidateId))
                {
                    var cand = model.CandidateScores.Where(x => x.Id == item.CandidateId).FirstOrDefault();
                    cand.VoteCount++;
                }

                // init singlevm
                SingleVote vote = new SingleVote
                {
                    SN         = count,
                    VoterName  = user.FirstName + " " + user.LastName,
                    VoterPhone = user.Phone,
                    VotedFor   = db.VoteUsers.Where(x => x.VoterId == item.CandidateId).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault()
                };

                //model.Votes.Add(vote);
            }
            ;

            model.Name = User.GetName();

            return(View("VoteResults", model));
        }