예제 #1
0
        public async Task <IActionResult> AreaOfCircle([FromBody] AreaOfCircleRequest areaOfCircleRequest)
        {
            try
            {
                var pi = await _constantsRepository.GetConstant("pi").ConfigureAwait(false);

                if (pi != null && !string.IsNullOrWhiteSpace(pi.Value))
                {
                    decimal piValue;
                    if (decimal.TryParse(pi.Value, out piValue))
                    {
                        Constants.Pi = piValue;
                    }
                }
                var calculator         = new SimpleCalculator();
                var areaOfCircleResult = calculator.AreaOfACircle(areaOfCircleRequest.radius);

                var response = new AreaOfCircleResponse()
                {
                    radius = areaOfCircleRequest.radius,
                    area   = areaOfCircleResult
                };

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failure calculating area of circle with radius {areaOfCircleRequest.radius}. {ex.ToString()}");

                return(StatusCode(500, "Internal Failure"));
            }
        }
        public IActionResult AreaOfCircle([FromBody] AreaOfCircleRequest areaOfCircleRequest)
        {
            try
            {
                var calculator         = new Calculator();
                var areaOfCircleResult = calculator.AreaOfACircle(areaOfCircleRequest.radius);

                var response = new AreaOfCircleResponse()
                {
                    radius = areaOfCircleRequest.radius,
                    area   = areaOfCircleResult
                };

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Failure calculating area of circle with radius {areaOfCircleRequest.radius}. {ex.ToString()}");

                return(StatusCode(500, "Internal Failure"));
            }
        }