public IActionResult BallotVote(BallotVoteViewModel model) { if (ModelState.IsValid) { string userId = _UserManager.GetUserId(User); var data = new VoterVotesBallot() { VoterName = userId, BallotName = model.BallotId, CandidateName = model.UserId }; if (_Context.Votes.SingleOrDefault(v => v.BallotName == model.BallotId && v.VoterName == userId) != null) { return(Unauthorized()); } _Context.Votes.Add(data); _Context.SaveChanges(); return(RedirectToAction(nameof(Dashboard))); } return(View(model)); }
public IActionResult FilterCandidates(BallotVoteViewModel model) { if (string.IsNullOrWhiteSpace(model.UserId)) { model.CandidateSearch.CandidateSelected = false; } else { model.CandidateSearch.CandidateSelected = true; } return(ViewComponent(typeof(CandidateViewComponent), model.CandidateSearch)); }