コード例 #1
0
        public async Task <IActionResult> PutPollUser([FromRoute] long id, [FromBody] PollUser pollUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pollUser.PollUserID)
            {
                return(BadRequest());
            }

            _context.Entry(pollUser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PollUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutPoll([FromRoute] long id, [FromBody] Poll poll)
        {
            var userID = User.Claims.FirstOrDefault(c => c.Type == "UserID").Value;

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != poll.PollID)
            {
                return(BadRequest());
            }

            var pollUser = await _context.PollUser.Where(p => p.PollID == id).Where(p => p.UserID == long.Parse(userID)).SingleOrDefaultAsync();

            pollUser.gestemd = true;
            _context.Entry(pollUser).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PollExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }