// PUT api/Customer/5 public HttpResponseMessage PutCustomer(int id, Customer customer) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != customer.id) { return Request.CreateResponse(HttpStatusCode.BadRequest); } try { repo.updateCustomer(customer); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Customer public HttpResponseMessage PostCustomer(Customer customer) { if (ModelState.IsValid) { repo.AddCustomer(customer); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customer); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = customer.id })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public void deleteCustomer(Customer customer) { db.Customers.Remove(customer); db.SaveChanges(); }
public Customer updateCustomer(Customer customer) { db.Entry(customer).State = EntityState.Modified; db.SaveChanges(); }
public Customer AddCustomer(Customer customer) { db.Customers.Add(customer); db.SaveChanges(); }