I have Webapi service controller that supports two get method which distincts by parameter
Controller
public class DailyRecordController : BaseApiController
{
private IDailyBroadcastRepository _repo;
public DailyRecordController(IDailyBroadcastRepository repo)
{
_repo = repo;
}
public IQueryable<DailyBroadcast> Get(DateTime? date=null)
{
var dailyBroadcastList = new List<DailyBroadcast>();
try
{
dailyBroadcastList = _repo.GetDailyBroadcastByDate(date??DateTime.Now).ToList();
}
catch (Exception ex)
{
//Log
}
return dailyBroadcastList.AsQueryable();
}
public DailyBroadcast Get(int? Id)
{
var dailyBroadcast = new DailyBroadcast();
try
{
dailyBroadcast = _repo.GetDailyBroadcastById(Id);
}
catch (Exception ex)
{
//Log
}
return dailyBroadcast;
}
}
Config
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
When call api/DailyRecord/2017-06-01 it hits to method with id:integer method, never hits the method with datetime parameter.
I have also tried to route attribute but not affected.
[HttpGet]
[Route("{date:datetime}")]
I fact, when I commnet out the second method with id parameter, the service returns
The requested resource does not support http method 'GET'
How can I build this controller with two Get methods that supports both datetime and integer parameters?