public async Task <IActionResult> Round(RoundViewModel newRound) { IActionResult _result = new ObjectResult(false); NextRoundResult _nextRoundResult = null; GenericResult _genericResult = null; try { if (ModelState.IsValid) { Game game = _gameRepository.GetSingle(newRound.GameId); if (game != null) { if (game.ValidateMove(newRound.Move1) && game.ValidateMove(newRound.Move2)) { Round lastRound = _gameRepository.GetLastRound(game.Id); int roundNo = lastRound != null ? lastRound.RoundNo + 1 : 1; Round roundToAdd = new Round() { Move1 = newRound.Move1, Move2 = newRound.Move2, Game = game, RoundNo = roundNo }; bool gameOver = PlayRound(roundToAdd); _roundRepository.Add(roundToAdd); _roundRepository.Commit(); if (gameOver == true && game.WinnerId == game.Player1Id) { _nextRoundResult = new NextRoundResult() { Succeded = true, GameOver = true, Winner = game.Player1, Round = roundToAdd }; } else if (gameOver == true && game.WinnerId == game.Player2Id) { _nextRoundResult = new NextRoundResult() { Succeded = true, GameOver = true, Winner = game.Player2, Round = roundToAdd }; } else { _nextRoundResult = new NextRoundResult() { Succeded = true, GameOver = false, Winner = roundToAdd.Winner, Round = roundToAdd }; } _result = new ObjectResult(_nextRoundResult); return(_result); } else { var json = JsonConvert.SerializeObject(newRound); _genericResult = new GenericResult() { Succeeded = false, Message = "Move1 " + newRound.Move1 + " or Move2 " + newRound.Move2 + " are invalid for the game settings" }; _loggingRepository.Add(new Error() { Message = "Invalid Move1 or Move2 POST api/game/round Move1 " + newRound.Move1 + " Move2 " + newRound.Move2, DateCreated = DateTime.Now }); _loggingRepository.Commit(); _result = new ObjectResult(_genericResult); return(_result); } } else { var json = JsonConvert.SerializeObject(newRound); _genericResult = new GenericResult() { Succeeded = false, Message = "Game with id " + newRound.GameId + " was not found" }; _loggingRepository.Add(new Error() { Message = "Invalid Model POST api/game/round " + json, DateCreated = DateTime.Now }); _loggingRepository.Commit(); _result = new ObjectResult(_genericResult); return(_result); } } else { var json = JsonConvert.SerializeObject(newRound); _genericResult = new GenericResult() { Succeeded = false, Message = "Invalid parameter fields " + json }; _loggingRepository.Add(new Error() { Message = "Invalid Model POST api/game/round " + json, DateCreated = DateTime.Now }); _loggingRepository.Commit(); _result = new ObjectResult(_genericResult); return(_result); } } catch (Exception ex) { _genericResult = new GenericResult() { Succeeded = false, Message = ex.Message }; _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); _result = new ObjectResult(_genericResult); return(_result); } }