public async Task <ActionResult <PollVote> > PostVote(PollVote vote)
        {
            _context.PollVotes.Add(vote);
            await _context.SaveChangesAsync();

            return(Ok(vote));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateFriend(long id, Friend friend)
        {
            if (id != friend.FriendID)
            {
                return(BadRequest());
            }
            _context.Entry(friend).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Exemple #3
0
        public async Task <ActionResult <GetPollDto> > CreatePoll([FromBody] CreatePollDto dto)
        {
            long userID = Convert.ToInt64(User.Claims.FirstOrDefault(c => c.Type == "UserID").Value);

            Poll poll = new Poll()
            {
                Name    = dto.Name,
                OwnerID = userID,
                Answers = new List <PollAnswer>()
            };

            dto.Answers.ForEach(a => poll.Answers.Add(new PollAnswer()
            {
                Answer = a
            }));

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

            return(Ok(new GetPollDto()
            {
                PollID = poll.PollID,
                Name = poll.Name
            }));
        }
        public async Task <ActionResult <PollUser> > PostPollUser(PollUser pu)
        {
            _context.PollUsers.Add(pu);
            await _context.SaveChangesAsync();

            return(Ok(pu));
        }
Exemple #5
0
        public async Task <IActionResult> Create([Bind("ID,Description,Votes,Postcode")] Issue issue)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(issue);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }

            return(View(issue));
        }