// POST api/Treinamentos public HttpResponseMessage PostTreinamento(Treinamento treinamento) { if (ModelState.IsValid) { db.Treinamentoes.Add(treinamento); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, treinamento); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = treinamento.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Treinamentos/5 public HttpResponseMessage PutTreinamento(long id, Treinamento treinamento) { if (ModelState.IsValid && id == treinamento.Id) { db.Entry(treinamento).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, treinamento); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }