// POST api/Menu public HttpResponseMessage PostMenu(Menu menu) { if (ModelState.IsValid) { db.Menus.Add(menu); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, menu); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = menu.id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Menu/5 public HttpResponseMessage PutMenu(int id, Menu menu) { if (ModelState.IsValid && id == menu.id) { db.Entry(menu).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }