public bool UpdateCustomer(Customer instance) { try { Customer customer = Db.Customers.Find(instance.CustomerId); Type type = customer.GetType(); foreach(var info in type.GetProperties()) { if(info.CanWrite) { var value = info.GetValue(instance); if(value != null) { info.SetValue(customer, value, null); } } } Db.SaveChanges(); return true; } catch { return false; } }
public bool CreateCustomer(Customer instance) { try { if (instance.CustomerId == 0) { Db.Customers.Add(instance); Db.SaveChanges(); return true; } return false; } catch { return false; } }