public async Task <ApiResponse> ReplaceWord( [FromRoute] string code, [FromBody] ReplaceWordModel replaceWordModel) { (var game, var localPlayer) = await GetGameAndLocalPlayer(code); if (game.CanReplaceWord(localPlayer).IsFailure(out string message)) { return(BadRequest(message)); } if (!(game.WordTiles.SingleOrDefault(t => t.Word == replaceWordModel.Word) is WordTile tile)) { return(NotFound($"{replaceWordModel.Word} is not on the game board.")); } string word = string.Empty; do { word = WordList.Words[_randomAccessor.Random.Next(0, WordList.Words.Length)]; }while (game.WordTiles.Any(wt => wt.Word == word)); game.ReplaceWord(localPlayer, tile, word); await _gameUpdater.UpdateGame(game); return(Accepted("Organizer Replaced Word.")); }
public Task <ApiResponse> CurrentGameReplaceWord( [FromBody] ReplaceWordModel replaceWordModel) => ReplaceWord(User.GetGameCode(), replaceWordModel);