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> PutPlayer(int id, PlayerDTO playerDto) { Player player = playerDto.Update(_context.Players.Find(id), _context); if (id != player?.Id) { return(BadRequest()); } var oldPlayings = _context.Playings.Where(x => x.PlayerId == id).ToList(); _context.RemoveRange(oldPlayings); _context.Entry(player).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlayerExists(id)) { return(NotFound()); } else { throw; } } playerDto.Id = player.Id; return(Ok(playerDto)); }