public void VoteForCandidate(RequestVoterModel voter) { var candidate = _context.Candidates .Where(el => el.Id == voter.CandidateID) .Select(el => new { IdCandidate = el.Id }) .FirstOrDefault(); var isnNewUserExist = _context.Users.Any(p => p.UserPesel == voter.UserPesel); if (!isnNewUserExist && candidate != null) { _context.Users.Add(new User() { CandidatesId = candidate.IdCandidate, UserPesel = voter.UserPesel, }); _context.SaveChanges(); } }
public ActionResult AddCandidate([FromBody] RequestVoterModel model) { _voterService.VoteForCandidate(model); return(Ok()); }