I have a Web API 2 controller (PersonProfessionController) with the following PUT method:
[HttpPut]
[AcceptVerbs("PUT")]
public void Put([FromBody]PersonProfessionModel value)
{
try
{
this.MyProfessionManager.Save(value.ToPersonProfession());
}
catch (Exception ex)
{
this.LogManager.Error(ex);
}
}
For some reason, it is simply unavailable. It also does not appear on the api help overview page.
On the other hand, I have a method in my PersonController, for example:
[HttpPut]
[AcceptVerbs("PUT")]
public void Put([FromBody]PersonModel value)
{
try
{
this.MyPersonManager.Save(value.ToPerson());
}
catch (Exception ex)
{
this.LogManager.Error(ex);
}
}
This works great.
Question
Although the PUT method of PersonController is very similar to my PersonProfessionController, apart from the obvious differences, it works until the last one works (not even visible).
Any idea what is going on?
UPDATE
The full PersonProfessionController class for each request:
public class PersonProfessionController : ApiController
{
private IPersonProfessionManager PersonProfessionManager { get; set; }
private ILogManager LogManager { get; set; }
public PersonProfessionController(
IPersonProfessionManager PersonProfessionManager,
ILogManager logManager)
{
this.PersonProfessionManager = PersonProfessionManager;
this.LogManager = logManager;
}
[HttpGet]
public IHttpActionResult Get(string languageCode, Guid id)
{
try
{
var result = this.PersonProfessionManager.Get(languageCode, id);
if (result == null)
return NotFound();
return Ok(result);
}
catch (Exception ex)
{
this.LogManager.Error(ex);
}
return NotFound();
}
#region Save
[HttpPut]
[AcceptVerbs("PUT")]
public void Put([FromBody]PersonPersonProfessionModel value)
{
try
{
this.PersonProfessionManager.Save(value.ToPersonProfession());
}
catch (Exception ex)
{
this.LogManager.Error(ex);
}
}
#endregion
[HttpGet]
public IHttpActionResult LoadPersonProfessionsForPersonAndDossier(
string languageCode,
Guid dossierId,
Guid personId
)
{
try
{
var contextInformation = new ContextInformation
{
LanguageCode = languageCode,
DossierId = dossierId,
PersonId = personId
};
var result = this.PersonProfessionManager.LoadPersonProfessionsForPersonAndDossier(contextInformation);
if (result == null)
return NotFound();
return Ok(result);
}
catch (Exception ex)
{
this.LogManager.Error(ex);
}
return NotFound();
}
}
I changed the code manually to make it brand neutral, this can cause inconsistencies if I changed something differently.
And routing on request:
config.Routes.MapHttpRoute(
name: "Get PersonProfession",
routeTemplate: "api/personprofession/{languageCode}/{id}",
defaults: new
{
controller = "PersonProfession",
action = "Get",
languageCode = RouteParameter.Optional,
id = RouteParameter.Optional
});
config.Routes.MapHttpRoute(
name: "LoadPersonProfessionsForPersonAndDossier",
routeTemplate: "api/personprofession/LoadPersonProfessionsForPersonAndDossier/{languageCode}/{dossierId}/{personId}",
defaults: new
{
controller = "PersonProfession",
action = "LoadPersonProfessionsForPersonAndDossier",
languageCode = RouteParameter.Optional,
dossierId = RouteParameter.Optional,
personId = RouteParameter.Optional
});
config.Routes.MapHttpRoute(
name: "PersonProfession Put",
routeTemplate: "api/personprofession/save/",
defaults: new { controller = "PersonProfession", action = "Put" }
);