I have a Web API project that uses a default route of "api/{controller}/{id}" where "id" is optional. In most cases this is sufficient but in some cases I need attribute routing. In this specific case, I have "api/Customers/{customerID}/Orders/{orderID}" where customer ID is required and orderID is optional. Originally my code only required the Order ID but I needed a way to pull the orders for a particular customer so I used an attribute route on my methods to allow this.
I am able to perform GET operations without problem, but when I try to do a POST operation, I get a 500 error. What's odd though is my object gets created so the exception that gets thrown must be coming after the database insert is created but I cannot confirm this since my debugger doesn't work. My API is in a separate project from my UI and for whatever reason I cannot get my debugger to work in the API project so the breakpoints I have set don't work.
The last line of code in my POST method is this:
return CreatedAtRoute("DefaultApi", new { id = order.ID }, order);
The first argument of this method is the route name and the one listed above is for the default route specified in WebApiConfig.cs. This particular route however is different from the default:
[Route("api/Customers/{customerID:int}/Orders")]
Could this be the problem? Since the route in question uses two arguments, I would assume that I'd need to specify them in the routeValues (second) argument to the CreatedAtRoute method.
What do I need to do to make this work? I suspect I may have problems performing PUT and DELETE operations as well, but I need to create an object before I can modify or delete it.