public async Task <IEnumerable <Result> > Get()
        {
            List <Vote> votess = await _votesService.GetVotesList();

            List <Result> r      = new List <Result>();
            var           result = (votess.GroupBy(v => v.Candidate_id,
                                                   (key, group) => new { candidate_id = key, count = group.ToList().Count }));

            foreach (var item in result)
            {
                r.Add(new Result(item.candidate_id, item.count));
            }
            return(r);
        }
Пример #2
0
        public async Task <CollectionResults> Get()
        {
            List <Vote> votess = await _votesService.GetVotesList();

            List <Result>     r = new List <Result>();
            CollectionResults collectionResults = new CollectionResults();

            var result = (votess.GroupBy(v => v.Candidate_id,
                                         (key, group) => new { candidate_id = key, count = group.ToList().Count }));

            foreach (var item in result)
            {
                r.Add(new Result(item.candidate_id, item.count));
            }
            collectionResults.Resuts = r;
            return(collectionResults);
        }
        public async Task GetDeleteLast()
        {
            List <Candidate> candidatess = await _candidatesService.GetCandidatesList();

            List <Vote> votess = await _votesService.GetVotesList();

            if (candidatess.Count > 0)
            {
                Candidate cand = await _candidatesService.RemoveLastAsync();

                foreach (Vote v in votess)
                {
                    if (v.Candidate_id == cand.Id)
                    {
                        await _votesService.DeleteVote(v.Id);
                    }
                }
            }
        }