// POST api/QuoteApi public HttpResponseMessage PostQuotes(Quotes quotes) { if (ModelState.IsValid) { quotes.IdCustomer = 11; db.Quotes.Add(quotes); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, quotes); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = quotes.IdQuate })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/QuoteApi/5 public HttpResponseMessage PutQuotes(int id, Quotes quotes) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != quotes.IdQuate) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(quotes).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }