public HttpResponseMessage PutProduct(Product product) { if (product == null) return Request.CreateResponse(HttpStatusCode.BadRequest); try { _context.Entry<Product>(product).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); var result = product; return Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao alterar produto"); } }
public HttpResponseMessage PatchProduct(Product product) { if (product == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } try { _db.Entry(product).State = EntityState.Modified; _db.SaveChanges(); return Request.CreateResponse(HttpStatusCode.OK, product); } catch (Exception) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Falha ao alterar produto"); } }
public HttpResponseMessage PostProducts(Product product) { if (product == null) return Request.CreateResponse(HttpStatusCode.BadRequest); try { _context.Products.Add(product); _context.SaveChanges(); var result = product; return Request.CreateResponse(HttpStatusCode.Created, result); } catch (Exception) { return Request.CreateResponse(HttpStatusCode.InternalServerError, "Falha ao incluir produto"); } }
public HttpResponseMessage PostProduct(Product product) { if (product == null) { return Request.CreateResponse(HttpStatusCode.BadRequest); } try { _db.Products.Add(product); _db.SaveChanges(); return Request.CreateResponse(HttpStatusCode.Created, product); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Falha ao incluir produto"); } }