public JsonResult ChangeElectionStatus(int newStatus) { using (var electionRepository = new ElectionRepository()) using (var candidateRepository = new CandidateRepository()) { var election = electionRepository.GetElectionByElectionId(ElectionConductor.ElectionId((int)Session["UserId"])); if ((newStatus == 1) && election.NoVote) { var path = Server.MapPath("~/Content/Banners/NoVote.jpg"); var noVoteImage = System.IO.File.ReadAllBytes(path); candidateRepository.CreateCandidateWithPhoto(new Candidate { ElectionId = ElectionConductor.ElectionId((int)Session["UserId"]), Name = "No Vote" }, noVoteImage); } var result = electionRepository.ChangeElectionStatus(ElectionConductor.ElectionId((int)Session["UserId"]), newStatus); return new JsonResult { Data = new { isOk = result == 1 } }; } }
public ActionResult Results() { if (Session["UserId"] == null) return RedirectToAction("Index", "Home"); using (var electionRepository = new ElectionRepository()) { var election = electionRepository.GetElectionByElectionId(ElectionConductor.ElectionId((int)Session["UserId"])); var resultsModel = new ResultsModel { MaxVotes = election.MaxVotes }; return View(resultsModel); } }