Exemplo n.º 1
0
        public ActionResult Vote([FromQuery] ElectionTypeId electionType, Guid candidateId)
        {
            var voterIp = this.HttpContext.Connection.RemoteIpAddress.ToString();

            //TODO: Check whether this IP have voted

            var electionTypeName = string.Empty;

            switch (electionType)
            {
            case ElectionTypeId.NationalAssembly: electionTypeName = "Народно събрание"; break;

            case ElectionTypeId.PresidentalElections: electionTypeName = "Президентски избори"; break;

            case ElectionTypeId.EuropeanParliament: electionTypeName = "Избори за европейски парламент"; break;

            default: throw new InvalidOperationException("Invalid election type");
            }

            var voteModel = new VoteModel
            {
                Candidate        = this.electionsService.GetCandidate(candidateId),
                ElectionType     = electionType,
                VoterIp          = voterIp,
                ElectionTypeName = electionTypeName
            };

            return(View(voteModel));
        }
        public ActionResult List(ElectionTypeId id)
        {
            this.ViewData["ElectionsType"] = id;
            var candidates = this.electionsService.GetCandidates(id);

            return(View(candidates));
        }
Exemplo n.º 3
0
 public bool CheckIpHasVoted(string ip, ElectionTypeId electionType)
 {
     return(this.ctx.Votes.Any(v => v.VotedFromIp == this.encryptionManager.EncryptString(ip) && v.IsVerified));
 }
Exemplo n.º 4
0
 public IQueryable <Candidate> GetCandidates(ElectionTypeId electionType)
 {
     return(this.ctx.Candidates.Where(p => p.ParticipantInElections.Any(etype => etype.ElectionTypeId == electionType)));
 }
 public IEnumerable <CandidateModel> GetCandidates(ElectionTypeId electionType)
 {
     return(this.electionsManager.GetCandidates(electionType).To <CandidateModel>().ToList());
 }