// POST api/Admin public HttpResponseMessage PostProductWebAPI(ProductWebAPI productwebapi) { if (ModelState.IsValid) { db.ProductWebAPIs.Add(productwebapi); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, productwebapi); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = productwebapi.Id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/Admin/5 public HttpResponseMessage PutProductWebAPI(int id, ProductWebAPI productwebapi) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != productwebapi.Id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(productwebapi).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }