public async Task <IActionResult> Vote(int electionId)
        {
            var sql        = $@"select candidate.id, citizen.last_name, candidate.election_id from candidate
                         join citizen on citizen.id=candidate.citizen_id
                         where candidate.election_id={electionId};";
            var candidates = _context.Query <VoteResult>().FromSql(sql).ToList();

            return(View(candidates));
        }
示例#2
0
        public async Task <IActionResult> About()
        {
            var sql   = $@"with sum_of_candidates as(select count(id) as sum1 from vote),
                       sum_of_votes as(select candidate_id,count(candidate_id)as sum2 from vote group by candidate_id)
                       select cit.first_name,cit.last_name,(cast(sov.sum2 as float)/(select sum1 from sum_of_candidates)*100)as candidate_percent 
                       from sum_of_votes as sov join candidate as ca on ca.id=sov.candidate_id
                       join citizen as cit on cit.id=ca.citizen_id 
                       join election as el on el.id=ca.election_id 
                       group by cit.first_name,cit.last_name,candidate_percent;";
            var books = _context.Query <ElectionResult>().FromSql(sql).ToList();

            ViewData["Message"] = "Your application description page.";
            return(View(books));
        }