how to validate date field for if nothing is passed see the current date

Asked

Viewed 23 times

0

I have an endpoint as follows:

[HttpGet]
[ProducesResponseType(typeof(IEnumerable<TestsDto>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<IEnumerable<TestsDto>>> GetAsync(Guid textId, Guid phraseId, Guid heightId, Guid? weightId, Guid? productId, decimal? value, DateTime? date)
{
    
    var test= await _testingHandler.GetAsync(textId, phraseId, currencyId, heightId, weightId, value, date );
    return Ok(apps);
}

How do I validate, if the last field that is date no value is passed to it I always assign the current date in this field ?

  • date ?? DateTime.Now?

  • @LINQ can pass directly in the same string type parameter, in case string algumacoisa = "" ? so the variable is a string but if nothing passes it is always empty. In the case of the date I could not do

2 answers

0

-1

Hello, see if this works for you:

[HttpGet]
[ProducesResponseType(typeof(IEnumerable<TestsDto>), (int)HttpStatusCode.OK)]
public async Task<ActionResult<IEnumerable<TestsDto>>> GetAsync(Guid textId, Guid phraseId, Guid heightId, Guid? weightId, Guid? productId, decimal? value, DateTime? date)
{
    if (date == null)
         date = DateTime.Now;
    var test= await _testingHandler.GetAsync(textId, phraseId, currencyId, heightId, weightId, value, date );
    return Ok(apps);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.