//Get VotingResult public JsonResult GetVotingResult(int votingType) { VotingCardType type = ToVotingCardType(votingType); VotingResultView result = _votingCardSvc.CreateVotingResultVM(type); return(Json(result, JsonRequestBehavior.AllowGet)); }
public VotingCard(ShareHolder shareHolder, List <Candidate> candidates, VotingCardType type) : this() { if (shareHolder.StatusAtMeeting == StatusAtMeeting.Absent) { throw new InvalidOperationException("Could not create VotingCard for absent shareholder"); } if (candidates == null) { throw new ArgumentNullException(""); } this.ShareHolderId = shareHolder.ShareHolderId; this.VotingCardType = type; foreach (var candidate in candidates) { if (candidate.IsValidForVotingCard(type)) { var line = new VotingCardLine() { CandidateId = candidate.Id, CandidateName = candidate.Name, }; VotingCardLines.Add(line); } } this.NumberOfCandidates = VotingCardLines.Count(); this.NumberOfShares = shareHolder.NumberOfShares; }
public bool CanBeVoted(VotingCardType type) { if (type == VotingCardType.BODVotingCard) { return(this.CandidateType == CandidateType.BODCandidate); } else { return(this.CandidateType == CandidateType.BOSCandidate); } }
public VotingResultView CreateVotingResultVM(VotingCardType type) { //Create VotingResultVM var candidates = _context.Candidates.ToList(); var resultVM = new VotingResultView(candidates, type); //Accumulate from VotingCards var votingCards = _context.VotingCards.Include("VotingCardLines") .Where(v => v.VotingCardType == type) .ToList(); resultVM.Accumulate(votingCards); return(resultVM); }
public VotingResultVM CreateVotingResultVM(VotingCardType type) { //Create VotingResultVM var candidates = _context.Candidates.ToList(); var resultVM = new VotingResultVM(candidates, type); //Accumulate from VotingCards var votingCards = _votingCardRepo .AllIncluding(m => m.VotingCardLines) .Where(v => v.VotingCardType == type) .ToList(); resultVM.Accumulate(votingCards); return(resultVM); }
//used for create the list of candidates public VotingResultView(List <Candidate> candidates, VotingCardType type) { CandidateLines = new List <CandidateLine>(); foreach (var candidate in candidates) { if (candidate.CanBeVoted(type)) { var line = new CandidateLine() { Id = candidate.Id, Name = candidate.Name }; CandidateLines.Add(line); } } }
//Get VotingCards public async Task <JsonResult> GetVotingCards(int votingType) { VotingCardType type = ToVotingCardType(votingType); var allVotingCards = _context.VotingCards.Include("ShareHolder") .Where(m => m.VotingCardType == type); var result = allVotingCards.Select(m => new { m.Id, m.IsInvalid, m.IsVoted, m.NumberOfCandidates, NumberOfShares = m.ShareHolder.NumberOfShares, ShareHolderCode = m.ShareHolder.ShareHolderCode, ShareHolderName = m.ShareHolder.Name, AmtAlreadyVoted = m.AmtAlreadyVoted, ShareHolderId = m.ShareHolder.ShareHolderId }).ToListAsync(); return(Json(await result, JsonRequestBehavior.AllowGet)); }