public async Task <bool> CastVote(int candidateId, int categoryId, int voterId) { bool isVoteCasted = false; var voter = await VoterRepository.GetByIdAsync(voterId); var candidate = await CandidateRepository.GetByIdAsync(candidateId); var category = await CategoryRepository.GetByIdAsync(categoryId); if (voter != null && candidate != null && category != null) { var vote = await VoteRepository.FindAsync(s => s.CategoryId == categoryId && s.VoterId == voterId); // Check to verify if voter has already casted vote for category if (!vote.Any()) { var newVote = new Vote { VoterId = voterId, CategoryId = categoryId, CandidateId = candidateId }; var data = await VoteRepository.AddAsync(newVote); isVoteCasted = true; } } return(isVoteCasted); }
public async Task <bool> UpdateVoterInfo(int voterId, DateTime dob) { var isVoteUpdated = false; var voter = await VoterRepository.GetByIdAsync(voterId); if (voter != null) { voter.DOB = dob; await VoterRepository.UpdateAsync(voter); isVoteUpdated = true; } return(isVoteUpdated); }