public ActionResult Create(Candidate candidate, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { candidate.Candidate_ImagePath = Path.GetExtension(file.FileName); candidate.Candidate_Image = ConvertToBytes(file); } //if (ModelState.IsValid) //{ candidate.Candidate_ID = candidate.GenerateCandID(); candidate.Candidate_TotalVotes = 0; var admin = (string)Session["Admin_Username"]; candidate.Admin_Username = admin; if (db.Candidates.Any(x => x.Candidate_ID == candidate.Candidate_ID) || db.Candidates.Any(x => x.Candidate_StudentNumber == candidate.Candidate_StudentNumber)) { ModelState.Clear(); ViewBag.DuplicateMessage = "This candidate already exists."; return(View("Create")); } var studentNum = db.MockStudents.Find(candidate.Candidate_StudentNumber); if (studentNum == null) { ModelState.Clear(); ViewBag.ErrorMessage = "Invalid candidate! Not a registered DUT student!"; return(View("Create", candidate)); } var party = db.Parties.Find(candidate.Party_Name); if (party != null) { party.Party_NoOfCandidates += 1; db.Entry(party).State = EntityState.Modified; db.SaveChanges(); } else if (party == null) { ModelState.Clear(); ViewBag.ErrorMessage = "Incorrect Party!"; return(View("Create", candidate)); } db.Candidates.Add(candidate); db.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Registration Successfully."; return(View("Create", new Candidate())); }
public ActionResult Create([Bind(Include = "Student_Number,Student_Password,ConfirmPassword,Student_Email,Student_Gender,Student_DOB,Student_Course,Student_YearOfStudy,Student_Campus,Student_Voted,Student_RecoveryQ,Student_RecoveryA,Student_Image,Student_ImagePath")] Student student, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { student.Student_ImagePath = Path.GetExtension(file.FileName); student.Student_Image = ConvertToBytes(file); } if (ModelState.IsValid) { student.Student_Voted = "False"; if (db.Students.Any(x => x.Student_Number == student.Student_Number)) { ModelState.Clear(); ViewBag.DuplicateMessage = "You are already registered."; return(View("Create", student)); } var studentNum = db.MockStudents.Find(student.Student_Number); if (studentNum == null) { ModelState.Clear(); ViewBag.ErrorMessage = "Invalid student! You are not a registered DUT student!"; return(View("Create", student)); } //student.Student_Recovery = " "; db.Students.Add(student); db.SaveChanges(); try { WebMail.SmtpServer = "smtp.gmail.com"; WebMail.SmtpPort = 587; WebMail.SmtpUseDefaultCredentials = true; WebMail.EnableSsl = true; WebMail.UserName = ""; WebMail.Password = ""; WebMail.From = "*****@*****.**"; WebMail.Send(to: student.Student_Email, subject: "Good day applicant" + student.Student_Number, body: "Your registration, to the greatest voting app to be developed, has been successfully completed. Thank you for choosing E-Lect. You have made the right choice! if you keep making choices like this you are going places in life. \n" + "Thanking you Profoundly \n" + "The E-Lect Team", isBodyHtml: true); } catch (Exception) { } ModelState.Clear(); ViewBag.SuccessMessage = "Registration Successful."; return(View("Create", new Student())); //return RedirectToAction("Index"); } return(View(student)); }
public ActionResult EditVoteTime([Bind(Include = "ID,Start_Date,End_Date")] VoteTime voteTime) { if (ModelState.IsValid) { db.Entry(voteTime).State = EntityState.Modified; db.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Voting Time changed successfully!"; return(View("EditVoteTime")); } return(View(voteTime)); }
public ActionResult Create(Admin admin, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { admin.Admin_ImagePath = Path.GetExtension(file.FileName); admin.Admin_Image = ConvertToBytes(file); } if (db.Admins.Any(x => x.Admin_Email == admin.Admin_Email) || db.Admins.Any(x => x.Admin_Username == admin.Admin_Username)) { return(Json(new { error = true, message = "Admin Username already exists!" }, JsonRequestBehavior.AllowGet)); } else { db.Admins.Add(admin); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Create([Bind(Include = "PostImageID,Image,ImagePath")] PostImage postImage, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { postImage.ImagePath = Path.GetExtension(file.FileName); postImage.Image = ConvertToBytes(file); } int number = 0; var num = db.PostImages.ToList(); foreach (var n in num) { number++; } if (number == 0) { postImage.PostImageID = 0; } else { postImage.PostImageID = number; } if (ModelState.IsValid) { db.PostImages.Add(postImage); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(postImage)); }
public ActionResult Create(Party party, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { party.Party_ImagePath = Path.GetExtension(file.FileName); party.Party_Image = ConvertToBytes(file); } var admin = (string)Session["Admin_Username"]; party.Admin_Username = admin; party.Party_NoOfCandidates = 0; party.Party_TotalVotes = 0; if (db.Parties.Any(x => x.Party_Name == party.Party_Name) || db.Parties.Any(x => x.Party_Description == party.Party_Description)) { return(Json(new { error = true, message = "Party already exists!" }, JsonRequestBehavior.AllowGet)); } db.Parties.Add(party); db.SaveChanges(); return(Json(new { success = true, message = "Party create Successfully" }, JsonRequestBehavior.AllowGet)); }
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")); }