public IActionResult GetGame(string id) { Game outputGame = null; try { var loadedGame = _rouletteGame.GetGame(id); outputGame = new Game() { CylinderSize = loadedGame.CylinderSize, GameId = loadedGame.GameId, NumberOfTiggerPulls = loadedGame.NumberOfTiggerPulls }; } catch(KeyNotFoundException) { return new ObjectResult(new Status() { Message = "No game found" }) { StatusCode = 404 }; } if (outputGame == null) { return new ObjectResult(new Status() { Message = "Something went wrong when trying to create the game" }) { StatusCode = 400 }; } return new ObjectResult(outputGame) { StatusCode = 200 }; }
public IActionResult PostGames([FromBody]Game inputGame) { Game outputGame = null; try { var createdGame = _rouletteGame.CreateGame(inputGame.CylinderSize); outputGame = new Game() { CylinderSize = createdGame.CylinderSize, GameId = createdGame.GameId, NumberOfTiggerPulls = createdGame.NumberOfTiggerPulls }; } catch { return new ObjectResult(new Status() {Message="Something went wrong when trying to create the game" }) { StatusCode = 400 }; } if (outputGame == null) { return new ObjectResult(new Status() { Message = "Something went wrong when trying to create the game" }) { StatusCode = 400 }; } return new ObjectResult(outputGame) { StatusCode = 200 }; }