I having a issue with attribute based routing not working. I have set my prefix (http://localhost:6600/api/camps/ATL2018/talks) as you can see below and set a default route and it seems to work fine.
namespace TheCodeCamp.Controllers
{
[RoutePrefix("api/camps/{moniker}/talks")]
public class TalkController : ApiController
{
private readonly ICampRepository _repositiry;
private readonly IMapper _mapper;
public TalkController(ICampRepository repository, IMapper mapper)
{
_repositiry = repository;
_mapper = mapper;
}
[Route()]
public async Task<IHttpActionResult> Get(string moniker, bool includeSpeakers = false)
{
try
{
var results = await _repositiry.GetTalksByMonikerAsync(moniker, includeSpeakers);
return Ok(_mapper.Map<IEnumerable<TalkModel>>(results));
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
[Route("{id:int}")]
public async Task<IHttpActionResult> Get(string moniker,int id, bool includeSpeakers)
{
try
{
var result = await _repositiry.GetTalkByMonikerAsync(moniker, id, includeSpeakers);
if (result == null) return NotFound();
return Ok(_mapper.Map<TalkModel>(result));
}
catch(Exception ex)
{
return InternalServerError(ex);
}
}
}
}
This issue is when I run the below URL it returns the Not Found
http://localhost:6600/api/camps/ATL2018/talks/1
There is a talks for Id 1 and issue seems to be that it is not even hitting the [Route("{id:int}")] as I set a break point against it and it returns Not Found without hitting the break point.
Any advise would be greatly appreciated.