public void AddAWriteInCanididate() { var _context = new VotingContext(); var _manager = new VotingManager(); var builder = new RankingVoteTicketBuilder(); var RankingVoteItem = new RankingVoteItem { RankingVoteItemId = Guid.NewGuid(), PrimeCandidateItem = new VotingApp.Models.CandidateItem() { CandidateId = Guid.NewGuid(), Name = "Test", JobId = Guid.Parse("521C573E-91E8-47CA-ACBC-BF3D63706F29") }, SubCandidateItem = new VotingApp.Models.CandidateItem() { CandidateId = Guid.NewGuid(), Name = "Vice Test", JobId = Guid.Parse("057A2ED5-CDE9-44DB-9697-041B0F09555F") }, Ranking = 1 }; _manager.Context.RankingVotes.Add(builder.GetEntity(RankingVoteItem)); _manager.Context.SaveChanges(); }
public List <RankingVoteItem> GetRankedVoteItems() { var builder = new RankingVoteTicketBuilder(); var items = Context.RankingVotes.Include("PrimeCandidate").Include("SubCandidate") .Include("PrimeCandidate.Job").Include("SubCandidate.Job") .Select(builder.GetModel).Where(x => !x.IsWriteIn).ToList(); return(items); }
public List <RankingVoteItem> GetRankedVoteItemsByIds(List <Guid?> ids) { var builder = new RankingVoteTicketBuilder(); var items = Context.RankingVotes.Include("PrimeCandidate").Include("SubCandidate") .Include("PrimeCandidate.Job").Include("SubCandidate.Job") .Select(builder.GetModel).ToList(); items = items.Where(x => ids.Contains(x.RankingVoteItemId)).ToList(); return(items); }
public List <VoteResult> AddRankingWriteInToElection(List <VoteResult> electionResults, RankingVoteItem voteItem, Guid ballotId, RankingVoteItem existingVoteItem) { var primeCandidateItem = CheckForExistingPrimeCandidate(voteItem, existingVoteItem); var subCandidateItem = CheckForExistingSubCandidate(voteItem, existingVoteItem); var rankingVoteId = Context.RankingVotes.FirstOrDefault(x => x.PrimeCandidateId == primeCandidateItem.CandidateId || x.SubCandidateId == subCandidateItem.CandidateId); if (rankingVoteId == null) { var rankingVoteItem = new RankingVoteItem { RankingVoteItemId = Guid.NewGuid(), PrimeCandidateItem = primeCandidateItem, SubCandidateItem = subCandidateItem, IsWriteIn = true }; var builder = new RankingVoteTicketBuilder(); Context.RankingVotes.Add(builder.GetEntity(rankingVoteItem)); Context.SaveChanges(); electionResults.Add(new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballotId, RankingVoteId = rankingVoteItem.RankingVoteItemId, Ranking = voteItem.Ranking, }); } else { electionResults.Add(new VoteResult { VoteResultsId = Guid.NewGuid(), BallotId = ballotId, RankingVoteId = rankingVoteId.RankingVoteId, Ranking = voteItem.Ranking, }); } return(electionResults); }