Beispiel #1
0
        public async Task <IActionResult> AddVote(string urlCode, int optionId)
        {
            Poll   poll   = _pollRepository.GetPollByUrlCode(urlCode);
            Option option = _pollRepository.GetOption(optionId);

            if (poll == null || option == null)
            {
                return(NotFound());
            }

            if (option.PollId != poll.PollId)
            {
                return(BadRequest());
            }

            _pollRepository.AddOneVote(option);

            try
            {
                _pollRepository.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_pollRepository.OptionExists(optionId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }