protected override Product PatchEntity(int key, Delta <Product> patch) { if (!ModelState.IsValid) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } Product product = data.Products.Find(key); if (product == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } patch.Patch(product); data.Entry(product).State = EntityState.Modified; try { data.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(product); }
// PUT api/ProductTypes/5 public HttpResponseMessage PutProductType(int id, ProductType producttype) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (id != producttype.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } data.Entry(producttype).State = EntityState.Modified; try { data.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); }
// PUT api/Products/5 public HttpResponseMessage Put([FromODataUri] int key, Product product) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } if (key != product.Id) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } data.Entry(product).State = EntityState.Modified; try { data.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.NoContent)); }