I have been trying to figure out what is going wrong for a few hours now and i just can't find what is going wrong.
Via the Mvc application the put method doesn't get hit, the request doesn't happen. But when i test it in fiddler the PutMethod in the api works.
Hopefully someone can clear things up for me.
Also pointers for a better structure or some good documentation are welcome .
public void UpdateWerknemerCompetentieDetail(int wnID, int WNC, CompetentieWerknemerDetail detail)
{
using (HttpClient client = new HttpClient())
{
string token = (string)HttpContext.Current.Session["token"];
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var wn = GetWerknemerById(wnID);
//var wnc = wn.CompetentiesWerknemer.Select(c => c).Where(c => c.ID == WNC).FirstOrDefault();
detail.CompetentieWerknemerID = WNC;
//wnc.CompetentieWerknemerDetail = detail;
var url = String.Format(URL + "PutDetails?id=" + WNC);
var json = JsonConvert.SerializeObject(detail, new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
});
var response = client.PutAsync(url, new StringContent(json, Encoding.UTF8, "application/json"));
}
}
The above code is my service that should make the request to the api.
Here is the web api IHttpActionResult method (the put method).
[Route("PutDetails")]
[HttpPut]
public IHttpActionResult PutWerknemerCompetentieDetails(int id, [FromBody]CompetentieWerknemerDetail cwn)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != cwn.CompetentieWerknemerID)
{
return BadRequest();
}
//_db.Entry(cwn).State = EntityState.Modified;
try
{
_db.CompetentieWerknemerDetail.Add(cwn);
_db.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!WerknemerExist(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}