public ActionResult Edit([Bind(Include = "CandidatePosition_ID,CandidatePosition_Description")] CandidatePosition candidatePosition) { if (ModelState.IsValid) { db.Entry(candidatePosition).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(candidatePosition)); }
public ActionResult doForgotPasswordUpdate(string Answer, string NewPassword, string ConfirmNewPassword, string IDNumber) { using (VotingSystemProjectEntities3 db = new VotingSystemProjectEntities3()) { var ans = registerVoter.HashedData(Answer); var idnum = registerVoter.HashedData(IDNumber); var search = db.Voters.Where(x => x.VoterIDNumber == idnum && x.SecurityQuestionAnswer == ans).FirstOrDefault(); if (search != null) { if (NewPassword == ConfirmNewPassword) { string hassednew = registerVoter.HashedData(NewPassword); string hassedcnew = registerVoter.HashedData(ConfirmNewPassword); search.VoterPassword = hassednew; db.SaveChanges(); TempData["success"] = "Your Password has been updated"; return(RedirectToAction("Voterlogin")); } } else { TempData["message"] = "Your your Security Question Answer was incorrect! Please try again!"; return(RedirectToAction("ForgotPassword", new { IDnum = IDNumber })); } } TempData["message"] = "Your Password was not updated"; return(RedirectToAction("VoterLogin")); }
public ActionResult doUpdatePassword(string Answer, string NewPassword, string ConfirmNewPassword, string VoterGUID, string id) { VoterVM voterVM = TempData["voterVM"] as VoterVM; registerVoter.voterView = voterVM; using (VotingSystemProjectEntities3 db = new VotingSystemProjectEntities3()) { var ans = registerVoter.HashedData(Answer); var vid = Convert.ToInt32(id); var search = db.Voters.Where(x => x.VoterID == vid && x.SecurityQuestionAnswer == ans).FirstOrDefault(); if (search != null) { if (NewPassword == ConfirmNewPassword) { string hassednew = registerVoter.HashedData(NewPassword); string hassedcnew = registerVoter.HashedData(ConfirmNewPassword); search.VoterPassword = hassednew; db.SaveChanges(); TempData["success"] = "Your Password has been updated"; return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID })); } } else { TempData["message"] = "Your Security Question Answer was wrong! Please try again!"; return(RedirectToAction("ChangePasswordVoter", new { VoterGUID = registerVoter.voterView.voter.GUID, id = registerVoter.voterView.voter.VoterID })); } } TempData["message"] = "An Error Occured!"; return(RedirectToAction("VoterHomePage", new { VoterGUID = registerVoter.voterView.voter.GUID })); }
public void RefreshGUID(VotingSystemProjectEntities3 db) { db.Configuration.ProxyCreationEnabled = false; voter.GUID = Guid.NewGuid().ToString(); voter.GUIDTimeStamp = DateTime.Now.AddMinutes(30); var g = db.Voters.Where(x => x.GUID == voter.GUID).Count(); if (g > 0) { RefreshGUID(db); } else { var u = db.Voters.Where(z => z.VoterID == voter.VoterID).FirstOrDefault(); db.Entry(u).CurrentValues.SetValues(voter); db.SaveChanges(); } }
public ActionResult AddNewCandidate(string StaffGUID, string id, string FirstNames, string LastName, [Bind(Include = "ProvinceID, CandidatePosition_ID, PartyID")]Candidate candidate) { ViewBag.message = TempData["message"]; ViewBag.success = TempData["success"]; if (StaffGUID != null) { if (FirstNames != null && LastName != null && candidate.PartyID != null && candidate.ProvinceID != null && candidate.CandidatePosition_ID != null) { var search = db.Candidates.Where(x => x.CandidatePosition_ID == candidate.CandidatePosition_ID && x.PartyID == candidate.PartyID).FirstOrDefault(); if (search == null) { Candidate candidate1 = new Candidate(); candidate1.CandidateFirstNames = FirstNames; candidate1.CandidateLastName = LastName; candidate1.CandidatePosition_ID = candidate.CandidatePosition_ID; candidate1.ProvinceID = candidate.ProvinceID; candidate1.PartyID = candidate.PartyID; db.Candidates.Add(candidate1); db.SaveChanges(); TempData["success"] = "The Candidate Has Been Registered"; return RedirectToAction("StaffHomePage", "Staff", new { StaffGUID = StaffGUID }); } else { TempData["message"] = "This Candidate Already Exists for this party Please Update the Candidate Instead"; return RedirectToAction("RegisterCandidate", new { StaffGUID = StaffGUID, id = id }); } } else { TempData["message"] = "Please Ensure That All Information Has Been Enetred"; return RedirectToAction("RegisterCandidate", new { StaffGUID = StaffGUID, id = id }); } } else { TempData["message"] = "Your Session Has Expired! Please Login Again!"; return RedirectToAction("StaffLogin", "Staff"); } }
public ActionResult AddNewVoter(string VoterIDNumber, string FirstName, string LastName, string Email, string PhoneNumber, [Bind(Include = "SuburbID, ProvinceID, CityOrTownID, SecurityQuestionID")] Voter voter, string Address, string Password, string ConfrimPassword, string SecurityAnswer) { if (VoterIDNumber != null) { var EncrypVoterID = registerVoter.HashedData(VoterIDNumber); var searchID = db.Voters.Where(x => x.VoterIDNumber == EncrypVoterID).FirstOrDefault(); if (searchID == null) { var SearchEmail = db.Voters.Where(j => j.VoterEmail == Email).FirstOrDefault(); if (SearchEmail == null) { var SearchPhone = db.Voters.Where(g => g.VoterPhoneNumber == PhoneNumber).FirstOrDefault(); if (SearchPhone == null) { if (PhoneNumber.Length == 10) { var EncrypPassword1 = registerVoter.HashedData(Password); var EncrypPassword2 = registerVoter.HashedData(ConfrimPassword); var EncrypSecurityQuestionAnswer = registerVoter.HashedData(SecurityAnswer); if (EncrypPassword1 == EncrypPassword2) { Voter v = new Voter(); v.VoterIDNumber = EncrypVoterID.ToString(); v.VoterPassword = EncrypPassword1.ToString(); v.VoterFirstNames = FirstName.ToString(); v.VoterLastName = LastName.ToString(); v.VoterEmail = Email.ToString(); v.VoterPhoneNumber = PhoneNumber.ToString(); v.VoterStreetAddress = Address.ToString(); v.VotePartyStatus = false; v.VotePartyStatus = false; v.SecurityQuestionAnswer = EncrypSecurityQuestionAnswer.ToString(); v.SecurityQuestionID = voter.SecurityQuestionID; v.SuburbID = voter.SuburbID; v.ProvinceID = voter.ProvinceID; v.CityorTownID = voter.CityorTownID; v.GUID = Guid.NewGuid().ToString(); v.GUIDTimeStamp = DateTime.Now; db.Voters.Add(v); db.SaveChanges(); TempData["success"] = "Registration was successfull!"; return(RedirectToAction("VoterLogin")); } else { TempData["message"] = "your passwords do not match Please try again"; RedirectToAction("RegisterVoter"); } } else { TempData["message"] = "The Phone Number is not the right length!"; RedirectToAction("RegisterVoter"); } } else { TempData["message"] = "The Phone Number is already in use please use a different one."; RedirectToAction("RegisterVoter"); } } else { TempData["message"] = "Email is already in use, please use a different one."; RedirectToAction("RegisterVoter"); } } else { TempData["message"] = "The user already exists please login!"; RedirectToAction("VoterLogin"); } } else { TempData["message"] = "Please enter a valid ID number!"; return(RedirectToAction("RegisterVoter")); } TempData["message"] = "An error has occured! please try again"; return(RedirectToAction("RegisterVoter")); }