I would like to check if any variable is empty or null in other words I would like to check if all parameters are sent. I have this code but it isn't working.
[HttpGet]
[Route("{regid}/{year}")]
public HttpResponseMessage Get(string regid, int? year, string un, string ps)
{
var isRegIDNumeric = int.TryParse(regid, out _);
if (!isRegIDNumeric || year == null || (String.IsNullOrEmpty(un)) || (String.IsNullOrEmpty(ps)))
{
...
}
If I call like this, one parameter is missing, IF isn't working
localhost/test/?regid=001&year=2019&un=ws.test
I got this message:
<Error>
<Message>No HTTP resource was found that matches the request URI
'localhost/test/?regid=001&year=2019&un=ws.test'.
</Message>
<MessageDetail>No action was found on the controller 'test' that matches
the request.
</MessageDetail>
</Error>
If I call with all parameters everything is OK, whole procedure is executed.
localhost/test/?regid=001&year=2019&un=ws.test&ps=test
When I had only 2 variables ...
[HttpGet]
[Route("{regid}/{year}")]
public HttpResponseMessage Get(string regid, int? year)
{
var isRegIDNumeric = int.TryParse(regid, out _);
if (!isRegIDNumeric || year == null)
{
...
}
and called like this, one parameter is missing ...
localhost/test/?regid=001
Everything was OK, IF was regularly executed.
How to make functional IF with all 4 variables if any of them is null or empty?