public async Task<IHttpActionResult> Put([FromODataUri] int key, Customer update) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != update.CustomerId) { return BadRequest(); } db.Entry(update).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(key)) { return NotFound(); } else { throw; } } return Updated(update); }
public async Task<IHttpActionResult> Post(Customer Customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Customers.Add(Customer); await db.SaveChangesAsync(); return Created(Customer); }
public Customer AddCustomer(Customer customer) { var existingCustomer = FindCustomer(customer.CustomerId); if (existingCustomer != null) { return existingCustomer; } _customers.Add(customer); return customer; }
public bool UpdateCustomer(int id, Customer customer) { if (id != customer.CustomerId) { return false; } var index = _customers.FindIndex(p => p.CustomerId == id); if (index == -1) { return false; } _customers[index] = customer; return true; }
private async Task PreProcessCustomerAsync(Customer customer) { customer.FirstName = "We did it"; }