I want to have two endpoints to my API method:
api/bids/
and
api/bids/{yyyy-MM-dd}
In first case i will map undefined date as today
I tried to make this way, but it did not work:
[RoutePrefix("api/bids")]
public class BidsController : ApiController
{
[HttpGet, Route("api/bids/{dateTime?}")]
public async Task<IHttpActionResult> GetBids(DateTime? dateTime = null)
{
var correctDate = (dateTime != null) && (dateTime.Value >= DateTime.Now.Date);
DateTime date = correctDate ? dateTime.Value : DateTime.Now.Date;
try
{
return Ok(date);
}
catch (Exception ex)
{
string errorMessage = ex.Message;
return BadRequest(errorMessage);
}
}
}
How i can use optional date parameter with attribute routing in my case?