Ejemplo n.º 1
0
        public JsonResult AddVoter(string voterId)
        {
            using (var voterRepository = new VoterRepository())
            {
                var result = voterRepository.CreateVoter(new Voter { ElectionId = ElectionConductor.ElectionId((int)Session["UserId"]), IdentityNumber = voterId });

                return new JsonResult
                {
                    Data = new { isOk = result }
                };
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            if (Session["UserId"] == null)
                return RedirectToAction("Index", "Home");

            using (var electionRepository = new ElectionRepository())
            using (var candidateRepository = new CandidateRepository())
            using (var voterRepository = new VoterRepository())
            {
                if (electionRepository.GetElectionByUserId((int)Session["UserId"]) == null)
                {
                    electionRepository.CreateElection(new Election
                    {
                        UserId = (int)Session["UserId"],
                        Name = "My Election"
                    });
                }

                var election = electionRepository.GetElectionByUserId((int)Session["UserId"]);

                var electionIndexModel = new ElectionIndexModel
                {
                    Setup = new ElectionSetupModel
                    {
                        Name = election.Name,
                        Status = election.Status,
                        MinVotes = election.MinVotes,
                        MaxVotes = election.MaxVotes,
                        NoVote = election.NoVote
                    },
                    Candidates = candidateRepository.GetCandidatesForElectionId(ElectionConductor.ElectionId((int)Session["UserId"])).OrderBy(x => x.Name).ToList(),
                    VotersCount = voterRepository.GetVotersForElectionId(ElectionConductor.ElectionId((int)Session["UserId"])).Count
                };

                return View(electionIndexModel);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Index(HttpPostedFileBase file)
        {
            if (file != null && file.ContentLength > 0)
            {
                var voterRegisterFile = handleUploadedFile(file);

                using (var voterRepository = new VoterRepository())
                {
                    voterRepository.DeleteVotersForElectionId(ElectionConductor.ElectionId((int)Session["UserId"]));

                    foreach (var voter in voterRegisterFile.Voters)
                    {
                        voterRepository.CreateVoter(new Voter
                        {
                            ElectionId = ElectionConductor.ElectionId((int)Session["UserId"]),
                            IdentityNumber = voter.IdentityNumber
                        });
                    }
                }
            }
            return RedirectToAction("Index");
        }