示例#1
0
        public JsonResult ViewVotesCount()
        {
            using (var votesRepository = new VotesRepository())
            {
                var voteCountCount = votesRepository.GetTotalVoteCountFromVoteCount(ElectionConductor.ElectionId((int)Session["UserId"]));
                var voteRegisterCount = votesRepository.GetTotalVoteCountFromVoteRegister(ElectionConductor.ElectionId((int)Session["UserId"]));

                return new JsonResult
                {
                    Data = new { isOk = true, VoteCountCount = voteCountCount, VoteRegisterCount = voteRegisterCount }
                };
            }
        }
示例#2
0
        /*public JsonResult GetCandidates()
        {
            using (var candidateRepository = new CandidateRepository())
            {
                var candidateListModel = new CandidateListModel { CandidateList = candidateRepository.GetCandidatesForElectionId(ElectionConductor.ElectionId((int)Session["UserId"])).OrderBy(x => x.Name).ToList() };

                return new JsonResult
                {
                    Data = new { isOk = true, CandidateList = candidateListModel }
                };
            }
        }*/
        /*public JsonResult GetVoters()
        {
            using (var voterRepository = new VoterRepository())
            {
                var voterListModel = new VoterListModel { VoterList = voterRepository.GetVotersForElectionId(ElectionConductor.ElectionId((int)Session["UserId"])) };

                return new JsonResult
                {
                    Data = new { isOk = true, VoterList = voterListModel }
                };
            }
        }*/
        public JsonResult ViewVotes()
        {
            using (var votesRepository = new VotesRepository())
            using (var candidateRepository = new CandidateRepository())
            {
                var voteList = new List<CandidateVotes>();
                var candidateList = candidateRepository.GetCandidatesForElectionId(ElectionConductor.ElectionId((int)Session["UserId"]));

                foreach (var candidate in candidateList)
                {
                    var votes = votesRepository.GetVotesForElectionIdAndCandidateId(ElectionConductor.ElectionId((int)Session["UserId"]), candidate.CandidateId);
                    voteList.Add(new CandidateVotes { Candidate = candidate, Votes = votes });
                }

                var voteListModel = new VoteListModel { VoteList = voteList.OrderByDescending(x => x.Votes).ToList() };

                return new JsonResult
                {
                    Data = new { isOk = true, VoteList = voteListModel }
                };
            }
        }