I want to send a HttpResponse if a condition check in a helper method fails so the code after the condition check is never executed.
I am aware of the handy methods like "return Unauthorized()" which can be called in a controller but those can not be used in a helper method. I know that the helper method could return a boolean which is checked in an if clause however a one liner "AssertCondition()" is prefered. Is this possible?
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
AssertCondition();
//do other things
return Ok();
}
private void AssertCondition()
{
//check some condition
if (true == false)
{
//condition failed I want to send a http response here
}
}