public ActionResult doVoteProvincial(string VoterGUID, string id, string PartyID, string provinceID) { if (VoterGUID != null && PartyID != null && id != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false) { voterVM.RefreshGUID(db); VotingViewModel votingViewModel = new VotingViewModel(); votingViewModel.voterView = voterVM; if (votingViewModel.GetElectionDate() != null) { int ids = Convert.ToInt32(id); var v = db.Voters.Where(x => x.VoterID == ids).FirstOrDefault(); if (v != null) { //Gets the Election and increases the total votes by 1 Election getdateElection = votingViewModel.GetElectionDate(); ProvincialResult pr = new ProvincialResult(); pr.PartyID = Convert.ToInt32(PartyID); pr.ElectionID = getdateElection.ElectionID; pr.ProvincialResultsTotalVotes = 1; pr.ProvinceID = Convert.ToInt32(provinceID); v.VoteProvinceStatus = true; db.ProvincialResults.Add(pr); db.SaveChanges(); TempData["success"] = "You have successfully voted for a Provincial Government!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } else { TempData["message"] = "An Error Occured Please Try Again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } } else { TempData["message"] = "An Error Occured Please Try Again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = votingViewModel.voterView.voter.GUID, id = votingViewModel.voterView.voter.VoterID })); } } else { TempData["message"] = "An Error Occured Please Try Again"; return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id })); } } else { TempData["message"] = "An Error Occured Please try again!"; return(RedirectToAction("VoteProvincial", new { VoterGUID = VoterGUID, id = id })); } }
public ActionResult VoteProvincial(string VoterGUID, string id) { VotingViewModel votingViewModel = new VotingViewModel(); if (votingViewModel.GetElectionDate() != null) { if (VoterGUID != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VoteProvinceStatus == false) { voterVM.RefreshGUID(db); int ids = Convert.ToInt32(id); votingViewModel.voterView = voterVM; var v = db.Voters.Where(l => l.VoterID == ids).FirstOrDefault(); if (v != null) { votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(k => k.Party.PartyImage).Where(x => x.ProvinceID == v.ProvinceID && x.CandidatePosition_ID != 1).ToList(); return(View(votingViewModel)); } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = votingViewModel.voterView.voter.GUID })); } } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "An Error Occured Please try again"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "You can only vote on the set election date"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } }
public ActionResult VoteParty(string VoterGUID, string id) { VotingViewModel votingViewModel = new VotingViewModel(); if (votingViewModel.GetElectionDate() != null) { if (VoterGUID != null) { VoterVM voterVM = new VoterVM(); if (voterVM.IsLogedIn(db, VoterGUID) && voterVM.voter.VotePartyStatus == false) { voterVM.RefreshGUID(db); votingViewModel.voterView = voterVM; votingViewModel.listcandidate = db.Candidates.Include(y => y.Party).Include(j => j.Party.PartyImage).Where(x => x.CandidatePosition_ID == 1).ToList(); votingViewModel.partiesImages = db.PartyImages.ToList(); ViewBag.message = TempData["message"]; ViewBag.success = TempData["success"]; return(View(votingViewModel)); } else { TempData["message"] = "You have already voted!"; return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "An Error Occured Please try again"; return(RedirectToAction("VoterHomePage", "Voter", new { VoterGUID = VoterGUID })); } } else { TempData["message"] = "You can only vote on the set election date"; return(RedirectToAction("VoterHomePage", new { VoterGUID = VoterGUID })); } }