// PUT api/hijo/5 public HttpResponseMessage Puthijo(int id, hijo hijo) { if (ModelState.IsValid && id == hijo.idhijo) { db.Entry(hijo).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
// DELETE api/hijo/5 public HttpResponseMessage Deletehijo(int id) { hijo hijo = db.hijoes.Find(id); if (hijo == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } db.hijoes.Remove(hijo); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } return(Request.CreateResponse(HttpStatusCode.OK, hijo)); }
// POST api/hijo public HttpResponseMessage Posthijo(hijo hijo) { if (ModelState.IsValid) { if (hijoExists(hijo.idhijo)) { db.Entry(hijo).State = EntityState.Modified; db.SaveChanges(); } else { db.hijoes.Add(hijo); db.SaveChanges(); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, hijo); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = hijo.idhijo })); return(response); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }