Example #1
0
        public ActionResult <int> CheckNumber([FromRoute] string number)
        {
            var guessedNumber = NumberService.Validate(number);

            if (guessedNumber is null)
            {
                var errorMessage = string.Format(Resources.InvalidNumberMessage, Resources.LowerBound,
                                                 Resources.UpperBound);
                return(BadRequest(errorMessage));
            }

            Logger.Log($"Checking number {guessedNumber}...");
            if (guessedNumber < CorrectNumber)
            {
                Logger.Log("Unfortunately, this number is too low.");
                return(StatusCode(303, Resources.TooLowMessage));
            }

            if (guessedNumber > CorrectNumber)
            {
                Logger.Log("Unfortunately, this number is too high.");
                return(StatusCode(303, Resources.TooHighMessage));
            }

            Logger.Log("Awesome, this is the correct number!");
            return(Ok(Resources.CorrectGuessMessage));
        }