public ActionResult StudentLogin(Student student) { using (ELectDBEntities db = new ELectDBEntities()) { var studentNum = db.Students.Where(x => x.Student_Number == student.Student_Number).FirstOrDefault(); var password = db.Students.Where(x => x.Student_Password == student.Student_Password).FirstOrDefault(); if (studentNum == null && password == null) { ViewBag.ErrorMessage = "Incorrect Username and Password"; return(View("StudentLogin", student)); } else if (studentNum == null) { ViewBag.ErrorMessage = "Incorrect Username"; return(View("StudentLogin", student)); } else if (password == null) { ViewBag.ErrorMessage = "Incorrect Password"; return(View("StudentLogin", student)); } else { Session["Student_Number"] = student.Student_Number; return(RedirectToAction("StudentHome", "Home")); } } }
public ActionResult AdminLogin(Admin admin) { using (ELectDBEntities db = new ELectDBEntities()) { var username = db.Admins.Where(x => x.Admin_Username == admin.Admin_Username).FirstOrDefault(); var password = db.Admins.Where(x => x.Admin_Password == admin.Admin_Password).FirstOrDefault(); if (username == null && password == null) { ViewBag.ErrorMessage = "Incorrect Username and Password"; return(View("AdminLogin", admin)); } else if (username == null) { ViewBag.ErrorMessage = "Incorrect Username"; return(View("AdminLogin", admin)); } else if (password == null) { ViewBag.ErrorMessage = "Incorrect Password"; return(View("AdminLogin", admin)); } else { Session["Admin_Username"] = admin.Admin_Username; return(RedirectToAction("AdminHome", "Home")); } } }
public ActionResult Index() { String av = ""; using (ELectDBEntities db = new ELectDBEntities()) { av = av + "Candidates Taking Part in this Election \n" + "\n"; List <Candidate> ac = new List <Candidate>(); var list = db.Candidates.ToList(); foreach (var item in list) { var index = db.Parties.Find(item.Party_Name); if (index != null) { if (index.Party_Status == "Active" && item.Candidate_Status == "Active") { Candidate c = new Candidate(); av = av + ("Candidate ID : " + item.Candidate_ID + " Candidate Name: " + item.Candidate_Name + " Party Name:" + item.Party_Name + "\n" + "\n"); } } } QRCodeEncoder endcoder = new QRCodeEncoder(); Bitmap img = endcoder.Encode(av); img.Save(Server.MapPath("~/img.jpg"), ImageFormat.Jpeg); return(View()); } }
// GET: Votes/Create public ActionResult Create() { var time = db.VoteTimes.Find(1); ProductModel product = new ProductModel(); if ((time.Start_Date <= DateTime.Now.Date) && DateTime.Now.Date < time.End_Date) { using (ELectDBEntities db = new ELectDBEntities()) { List <Candidate> ac = new List <Candidate>(); var list = db.Candidates.ToList(); foreach (var item in list) { var index = db.Parties.Find(item.Party_Name); if (index != null) { if (index.Party_Status == "Active" && item.Candidate_Status == "Active") { Candidate c = new Candidate(); c.Candidate_ID = item.Candidate_ID; c.Candidate_Name = item.Candidate_Name; c.Candidate_MidName = item.Candidate_MidName; c.Candidate_Surname = item.Candidate_Surname; c.Candidate_Position = item.Candidate_Position; c.Candidate_Image = item.Candidate_Image; c.Candidate_ImagePath = item.Candidate_ImagePath; c.isChecked = item.isChecked; ac.Add(c); } } } product.Cand = ac.ToList <Candidate>(); } RedirectToAction("Create"); } else if (DateTime.Now.Date > time.Start_Date) { return(RedirectToAction("Construct")); } else if (time.End_Date == DateTime.Now.Date) { return(RedirectToAction("Construct")); } else { return(RedirectToAction("Construct")); } //ViewBag.Candidate_ID = new SelectList(db.Candidates, "Candidate_ID", "Candidate_Name"); //ViewBag.Party_ID = new SelectList(db.Parties, "Party_ID", "Party_Name"); //ViewBag.Student_Number = new SelectList(db.Students, "Student_Number", "Student_Password"); return(View(product)); }
public ActionResult Create(ProductModel product) { var studentNum = (int)Session["Student_Number"]; if (db.Votes.Any(x => x.Student_Number == studentNum)) { var selectedCandidate = product.Cand.Where(x => x.isChecked == true).ToList <Candidate>(); if (selectedCandidate != null) { foreach (var item in selectedCandidate) { int news = 0; int number = 0; var num = db.Votes.ToList(); if (num == null) { news = 1; } else { foreach (var n in num) { number++; } int count = 0; foreach (var l in num) { count++; if (count == number) { news = l.Vote_ID + 1; } } } var vote = new Vote(); vote.Vote_ID = news; vote.Student_Number = studentNum; vote.Candidate_ID = item.Candidate_ID; ELectDBEntities sis = new ELectDBEntities(); Candidate cands = sis.Candidates.Find(vote.Candidate_ID); if (cands != null) { cands.Candidate_TotalVotes += 1; sis.Entry(cands).State = EntityState.Modified; sis.SaveChanges(); } else if (cands == null) { ModelState.Clear(); ViewBag.ErrorMessage = "Incorrect Candidate!"; return(View("Create", vote)); } var partyIDs = cands.Party_Name; vote.Party_Name = partyIDs; ELectDBEntities ses = new ELectDBEntities(); var partys = ses.Parties.Find(vote.Party_Name); if (partys != null) { partys.Party_TotalVotes += 1; ses.Entry(partys).State = EntityState.Modified; ses.SaveChanges(); } db.Votes.Add(vote); db.SaveChanges(); } } else { ViewBag.ErrorMessage = "You have not selected any candidates to vote for"; return(View("Create")); } ViewBag.DuplicateMessage = "You have already voted!"; return(View("Create", product)); } try { var s = db.Students.Find(studentNum); WebMail.SmtpServer = "smtp.gmail.com"; WebMail.SmtpPort = 587; WebMail.SmtpUseDefaultCredentials = true; WebMail.EnableSsl = true; WebMail.UserName = ""; WebMail.Password = ""; WebMail.From = ""; WebMail.Send(to: s.Student_Email, subject: "Dearest applicant : " + s.Student_Number, body: "Your vote through the E-Lect online voting application has been successful. Please go ahead and share our apllication. Help a brother out. We appreciate your use of E-Lect. Voting is made easy through E-Lect.Viva E-Lect Viva! \n" + "Yours Gratefully \n" + "The E-Lect Team", isBodyHtml: true); } catch (Exception) { ViewBag.ErrorMessage = "Your internet connection slow and the email was not able to be sent to you."; } return(View("VoteSuccess")); }