public async Task <CollectionCandidates> GetAsync() { CollectionCandidates collectionCandidates = new CollectionCandidates(); List <Candidate> candidatess = await _candidatesService.GetCandidatesList(); collectionCandidates.Candidates = candidatess; return(collectionCandidates); }
public async Task <IActionResult> Put([FromBody] Candidate value, string newName) { if (value.Name != null && value.Name.ToString() != "") { List <Candidate> candidatess = await _candidatesService.GetCandidatesList(); Candidate val = candidatess.Find(c => c.Name == value.Name); val.Name = newName; await _candidatesService.UpdateAsync(val); return(new ObjectResult(_candidatesService.GetAllAsync())); } else { return(NotFound()); } }
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); } } votess.RemoveAll(c => c.Candidate_id == cand.Id); } }
public async Task <string> GetResultAsync() { BarChart chart = new BarChart(); List <Vote> votess = await _votesService.GetVotesList(); List <Candidate> candidatess = await _candidatesService.GetCandidatesList(); var result = votess.GroupBy(v => v.Candidate_id, (key, group) => new { candidate_id = key, count = group.ToList().Count }); chart.addColumn("string", "Candidate"); chart.addColumn("number", "Ratings"); foreach (var item in result) { var candidate = candidatess. Where(c => c.Id == item.candidate_id).FirstOrDefault(); if (candidate != null) { chart.addRowJson(candidate.Name, item.count.ToString()); } } return(chart.JSon()); }