public IHttpActionResult PutCustomers(int id, Customers customers) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != customers.Id) { return BadRequest(); } customers.ModifiedTime = DateTime.Now; db.Entry(customers).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomersExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult GetCustomers(int id) { Customers customers = db.Customers.Find(id); if (customers == null) { customers = new Customers(); } return Ok(customers); }
public IHttpActionResult PostCustomers(Customers customers) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Customers.Add(customers); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = customers.Id }, customers); }