public async Task <IActionResult> InvalidateVote(string id) { ElectionVote vote = await _context.ElectionVotes.FindAsync(id); if (vote == null) { StatusMessage = $"Error: Could not find vote with Id {id}"; return(RedirectToAction("ManageElections")); } vote.Invalid = !vote.Invalid; _context.ElectionVotes.Update(vote); await _context.SaveChangesAsync(); if (vote.Invalid) { StatusMessage = "Invalidated vote successfully."; } else { StatusMessage = "Revalidated vote successfully"; } return(RedirectToAction("ManageElections")); }
public ActionResult DeleteConfirmed(int id) { ElectionVote electionvote = db.ElectionVotes.Find(id); db.ElectionVotes.Remove(electionvote); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /Admin/ElectionVote/Details/5 public ActionResult Details(int id = 0) { ElectionVote electionvote = db.ElectionVotes.Find(id); if (electionvote == null) { return(HttpNotFound()); } return(View(electionvote)); }
public async Task <IActionResult> ProcessVote(string id, string choice) { User user = await _userManager.GetUserAsync(User); Election election = await _context.Elections.FindAsync(id); if (election == null) { StatusMessage = $"Error: Could not find election with Id {id}"; return(RedirectToAction("Elections")); } User chosen = await _context.Users.FindAsync(choice); if (chosen == null) { StatusMessage = $"Error: Could not find user with Id {choice}"; return(RedirectToAction("Elections")); } if (!(await chosen.IsEligibleForElection(election.Type, election.District))) { StatusMessage = $"Error: The user {chosen.Name} was not valid for this election."; return(RedirectToAction("Elections")); } if (!user.IsEmperor() && user.district != election.District) { StatusMessage = $"Error: You are not eligible to vote in {election.District}"; return(RedirectToAction("Elections")); } if (await _context.ElectionVotes.AsQueryable().AnyAsync(x => x.Election_Id == election.Id && x.User_Id == user.Id)) { StatusMessage = $"Error: You have already voted in this election!"; return(RedirectToAction("Elections")); } ElectionVote vote = new ElectionVote() { Date = DateTime.UtcNow, Choice_Id = choice, Election_Id = election.Id, Id = Guid.NewGuid().ToString(), User_Id = user.Id }; await _context.ElectionVotes.AddAsync(vote); await _context.SaveChangesAsync(); StatusMessage = $"Successfully voted for {chosen.Name}."; return(RedirectToAction("Elections")); }
// // GET: /Admin/ElectionVote/Edit/5 public ActionResult Edit(int id = 0) { ElectionVote electionvote = db.ElectionVotes.Find(id); if (electionvote == null) { return(HttpNotFound()); } ViewBag.CommitteeId = new SelectList(db.Committees, "Id", "Name", electionvote.CommitteeId); ViewBag.ElectionId = new SelectList(db.Elections, "Id", "Id", electionvote.ElectionId); //ViewBag.FacultyId_Nominee = new SelectList(db.Faculties, "Id", "First", electionvote.FacultyId_Nominee); ViewBag.FacultyId_Nominee = new SelectList(db.Faculties.OrderBy(f => f.Last).ThenBy(f => f.First).Select(f => new { Id = f.Id, FullName = f.Last + ", " + f.First }), "Id", "FullName", electionvote.FacultyId_Nominee); // ViewBag.FacultyId_Voter = new SelectList(db.Faculties, "Id", "First", electionvote.FacultyId_Voter); ViewBag.FacultyId_Voter = new SelectList(db.Faculties.OrderBy(f => f.Last).ThenBy(f => f.First).Select(f => new { Id = f.Id, FullName = f.Last + ", " + f.First }), "Id", "FullName", electionvote.FacultyId_Voter); return(View(electionvote)); }
public ActionResult Edit(ElectionVote electionvote) { if (ModelState.IsValid) { db.Entry(electionvote).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CommitteeId = new SelectList(db.Committees.OrderBy(c => c.Name), "Id", "Name", electionvote.CommitteeId); ViewBag.ElectionId = new SelectList(db.Elections, "Id", "Id", electionvote.ElectionId); //ViewBag.FacultyId_Nominee = new SelectList(db.Faculties, "Id", "First", electionvote.FacultyId_Nominee); ViewBag.FacultyId_Nominee = new SelectList(db.Faculties.OrderBy(f => f.Last).ThenBy(f => f.First).Select(f => new { Id = f.Id, FullName = f.Last + ", " + f.First }), "Id", "FullName", electionvote.FacultyId_Nominee); // ViewBag.FacultyId_Voter = new SelectList(db.Faculties, "Id", "First", electionvote.FacultyId_Voter); ViewBag.FacultyId_Voter = new SelectList(db.Faculties.OrderBy(f => f.Last).ThenBy(f => f.First).Select(f => new { Id = f.Id, FullName = f.Last + ", " + f.First }), "Id", "FullName", electionvote.FacultyId_Voter); return(View(electionvote)); }