Beispiel #1
0
        public IActionResult Vote(string token, VoteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Candidates = _candidatesService.GetList();
                return(View(model));
            }

            var foundToken = _tokensService.FindTokenByValue(token);

            if (foundToken == null)
            {
                return(BadRequest("Niewłaściwy token"));
            }

            _candidatesService.IncreaseCandidateVote(model.CandidateId.Value);
            _tokensService.RemoveToken(foundToken.ID);

            // Przekierowanie do widoku pokazującego wiadomość o pomyślnym głosowaniu
            return(RedirectToAction(nameof(VoteSucceeded)));
        }