public ActionResult Login(LoginViewModel verifyUser) { ElectionCatalog db = new ElectionCatalog(); User user = new User(); switch (verifyUser.UserType) { case "Voter": user = db.Users.Find(verifyUser.UserName); break; case "Candidate": user = db.Users.Find(verifyUser.UserName); break; case "Admin": user = db.Users.Find(verifyUser.UserName); break; } if (user.Password == verifyUser.Password && user != null) { Session.Add("UserName", user.UserName); Session["LoginStage"] = 1; ViewBag.IsValidLogIn = true; return(RedirectToAction("Index", "Home")); } else { ViewBag.IsValidLogIn = false; return(RedirectToAction("Login", "Account")); } }
public ActionResult ApproveProvincial(List <Election> notApproved) { ElectionCatalog db = new ElectionCatalog(); var approved = from Election in notApproved where Election.isApproved == true select Election; CandidateApplication candidateApplication = null; foreach (var item in approved) { candidateApplication = new CandidateApplication(); var city = from election in db.Elections where election.ID == item.ID select election.City; candidateApplication.City = city.FirstOrDefault() as string; candidateApplication.Candidate = (string)Session["UserName"]; candidateApplication.Election_Id = item.ID; candidateApplication.Level = "Provincial"; db.CandidateApplications.Add(candidateApplication); } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult CastVoteTo(Vote vote) { ElectionCatalog db = new ElectionCatalog(); db.Votes.Add(vote); db.SaveChanges(); return(View()); }
public ActionResult RegisterType(User user, FormCollection Form) { user.PicPath = SaveImage(user.PicPath.Substring(23, user.PicPath.Length - 23), user.UserName); ElectionCatalog db = new ElectionCatalog(); db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index", "Login")); }
public ActionResult Approve(List <User> notApproved) { ElectionCatalog db = new ElectionCatalog(); var approved = from User in notApproved where User.isApproved == true select User; foreach (var item in approved) { db.Users.Find(item.UserName).isApproved = true; } db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ApproveCandidate() { if (Session["UserName"] == null) { return(RedirectToAction("Index", "Login")); } ElectionCatalog db = new ElectionCatalog(); var notApproved = new List <User>(); IQueryable <User> temp = from User in db.Users where User.UserType == "Candidate" && User.isApproved == false select User; notApproved = temp.ToList <User>(); return(View(notApproved)); }
public ActionResult CastVote(string Level) { if (Session["UserName"] == null) { return(RedirectToAction("Index", "Login")); } else { Vote vote = new Vote(); ViewBag.Level = Level; ElectionCatalog db = new ElectionCatalog(); string city = db.Users.Find(Session["UserName"]).City.ToString(); //IQueryable<Election> elections = from Election in db.Elections // where Election.City == city && Election.Level == Level // select Election; //List<Election> ele = elections.ToList<Election>(); //var query = from Election in ele // join can in db.CandidateApplications // on new { Election.Level, Election.City } equals new { can.Level, can.City } // select new { can.Candidate, can.Election_Id, can.City }; List <Vote> Vote = new List <Vote>(); var query = from i in db.CandidateApplications where i.City == city && i.Level == Level select i; foreach (var i in query) { Vote.Add(new Vote { Candidate = i.Candidate.ToString(), Date = DateTime.Now, ElectionCity = i.City.ToString(), ElectionID = i.Election_Id.ToString(), Voter = Session["UserName"].ToString() }); } return(View(Vote)); } }
public ActionResult ApplyForProvincialSeat(/*string Level*/) { ElectionCatalog db = new ElectionCatalog(); if (Session["UserName"] == null) { return(RedirectToAction("Index", "Login")); } else { //ViewBag.Level = Level; //return View(); // User Candidate = new User(); string user = (string)Session["UserName"]; var Candidate = from candidate in db.Users where candidate.UserName.Equals(user) && candidate.isApproved == true select candidate; if (Candidate != null) { var notApplied = new List <Election>(); IQueryable <Election> temp = from City in db.Elections select City; notApplied = temp.ToList <Election>(); return(View(notApplied)); } return(RedirectToAction("Index", "CandidateHome")); } }