public async Task <Customer> UpdateCustomerAsync(Customer customer) { using (var context = new CustomersServiceDbContext()) { var cust = await context.Customers.FirstOrDefaultAsync(c => c.Id == customer.Id); if (cust != null) { cust.FirstName = customer.FirstName; cust.LastName = customer.LastName; cust.Address = customer.Address; cust.Phone = customer.Phone; cust.Email = customer.Email; context.Entry(cust).State = EntityState.Modified; } else { context.Customers.Attach(customer); } await context.SaveChangesAsync(); } return(customer); }
public async Task <Order> UpdateOrderAsync(Order order) { using (var context = new CustomersServiceDbContext()) { if (!context.Orders.Local.Any(o => o.Id == order.Id)) { context.Orders.Attach(order); } context.Entry(order).State = EntityState.Modified; await context.SaveChangesAsync(); } return(order); }