예제 #1
0
        //public async Task<IActionResult> PutTodoItem(long id, TodoItem todoItem)
        public async Task <ActionResult <User> > UpdateUser(long id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            //return NoContent();
            return(user);
        }
예제 #2
0
        public async Task <IActionResult> PutRoleGame(int id, RoleGameDTO roleGamedto)
        {
            RoleGame roleGame = roleGamedto.Update(_context.RoleGames.Find(id), _context);

            if (id != roleGame?.Id)
            {
                return(BadRequest());
            }

            var oldPlayings = _context.Playings.Where(x => x.RoleGameId == id).ToList();

            _context.RemoveRange(oldPlayings);
            _context.Entry(roleGame).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RoleGameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            roleGamedto.Id = roleGame.Id;
            return(Ok(roleGamedto));
        }
 public async Task <IActionResult> PutRole([FromRoute] int id, [FromBody] Role role)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != role.RoleId)
     {
         return(BadRequest());
     }
     _context.Entry(role).State = EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!RoleExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }
예제 #4
0
        public async Task <ActionResult <RoleGameDTO> > JoinPlayer(int id, int gameid)
        {
            var player = await _context.Players.FindAsync(id);

            var game = await _context.RoleGames.FindAsync(gameid);

            if (player == null || game == null)
            {
                return(NotFound());
            }

            _context.Playings.Add(new Playing()
            {
                RoleGame = game, Player = player
            });
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new RoleGameDTO(game, _context)));
        }