public IActionResult CalculateX(string formula, double?x) { if (formula == null || x == null) { var bad2 = new { status = "error", result = "wrong input!" }; return(BadRequest(bad2)); } RPN rpn = new RPN(formula, (double)x); if (rpn.CheckInput()) { var good = new { status = "ok", result = rpn.CalculateValueOfGivenX() }; return(Ok(good)); } var bad = new { status = "error", result = rpn.Message() }; return(BadRequest(bad)); }