//id based on route parameter, modify customers public void PutCustomer(string id, Customer customer) { var matchingCustomer = _Context.Customers.FirstOrDefault(c => c.CustomerID == id); if (matchingCustomer != null) { SetChangedProperties(matchingCustomer, customer); _Context.SaveChanges(); } }
private void SetChangedProperties(Customer matchingCustomer, Customer customer) { //Attaches the given entity to the context underlying the set. That is, the entity is placed into the context in the Unchanged state, just as if it had been read from the database. _Context.Customers.Attach(customer); _Context.SaveChanges(); }
//PUT/POST/DELETE //AddCustomer public void PostCustomer(Customer customer) { _Context.Customers.Add(customer); }