public Models.GuessResponse GuessSecret(Models.GuessParam guess) { guessDAO = new DAO.GuessDAO(); var validation = ValidateInput(guess); if (validation.ResponseId == 0) { var secret = guessDAO.getSecret(guess.GameId); if (guess.Guess.Count() != secret.Count()) { return(new Models.GuessResponse { ResponseId = 2, ResponseMessage = "Invalid Guess" }); } var guessResults = TryGuess(secret, guess.Guess); var solved = guessResults.Exact == guess.Guess.Count(); var results = guessDAO.SaveAndReturnGuesses(guess, guessResults, solved); return(new Models.GuessResponse { GameId = guess.GameId, Exact = guessResults.Exact, Near = guessResults.Near, Guess = guess.Guess, Guesses = results, GameSolved = solved, ResponseId = validation.ResponseId, ResponseMessage = validation.ResponseMessage }); } else { return(new Models.GuessResponse { ResponseId = validation.ResponseId, ResponseMessage = validation.ResponseMessage }); } }
private Models.BaseResponse ValidateInput(Models.GuessParam game) { if (string.IsNullOrEmpty(game.Guess)) { return(new Models.BaseResponse { ResponseId = 2, ResponseMessage = "Invalid Guess" }); } if (string.IsNullOrEmpty(game.GameId)) { return(new Models.BaseResponse { ResponseId = 3, ResponseMessage = "Invalid Game ID" }); } else { DateTime?validation = guessDAO.ValidateGameID(game.GameId); if (!validation.HasValue) { return(new Models.BaseResponse { ResponseId = 3, ResponseMessage = "Invalid Game ID" }); } else if (validation.Value != DateTime.MinValue) { return(new Models.BaseResponse { ResponseId = 4, ResponseMessage = "Game Solved" }); } } return(new Models.BaseResponse { ResponseId = 0, ResponseMessage = "OK" }); }
public Models.GuessResponse Post([FromBody] Models.GuessParam value) { var response = guessService.GuessSecret(value); return(response); }