コード例 #1
0
        public bool ValidateZero(CalculatorDividePayload payload, out ActionResult <CalculatorValue> result)
        {
            foreach (var value in payload.Values)
            {
                if (_zeroValidator.Validate(value))
                {
                    result = new BadRequestObjectResult(ErrorMessages.NULL_DIVISION);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
コード例 #2
0
        public ActionResult <CalculatorValue> Divide([FromBody] CalculatorDividePayload payload)
        {
            if (_validator.ValidateNull(payload, out var nullResult))
            {
                return(nullResult);
            }

            if (_validator.ValidateZero(payload, out var zeroResult))
            {
                return(zeroResult);
            }

            var calculatioResult = _calculator.Divide(payload.Values, payload.Dividend);

            calculatioResult.CorrelationId = payload.CorrelationId;
            return(Ok(calculatioResult));
        }
コード例 #3
0
        public bool ValidateNull(CalculatorDividePayload payload, out ActionResult <CalculatorValue> result)
        {
            if (_nullValidator.Validate(payload.Dividend))
            {
                result = new BadRequestObjectResult(string.Format(ErrorMessages.NULL_VALUE_TEMPLATE, nameof(payload.Dividend)));
                return(true);
            }

            foreach (var vaues in payload.Values)
            {
                if (_nullValidator.Validate(vaues))
                {
                    result = new BadRequestObjectResult(ErrorMessages.NULL_VALUE);
                    return(true);
                }
            }

            result = null;
            return(false);
        }