示例#1
0
        public async Task <IActionResult> PutPolls(int id, PollsDTO pollsDTO)
        {
            if (id != pollsDTO.Id)
            {
                return(BadRequest());
            }

            var poll = await _context.Polls.FindAsync(id);

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

            poll.QuestionId = pollsDTO.QuestionId;
            poll.Poll       = pollsDTO.Poll;
            poll.Votes      = pollsDTO.Votes;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException) when(!PollsExists(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
示例#2
0
        public async Task <ActionResult <PollsDTO> > PostPolls(PollsDTO pollsDTO)
        {
            var poll = new Polls
            {
                Poll = pollsDTO.Poll
            };

            _context.Polls.Add(poll);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(
                       nameof(GetPoll),
                       new { id = poll.Id },
                       PollsToDTO(poll)));
        }