public void UpdateCustomer(Customer customer) { NorthwindEntities model = new NorthwindEntities(); var customerToBeUpdated = (from cust in model.Customers where cust.CustomerID == customer.CustomerID select cust).FirstOrDefault(); foreach (PropertyInfo property in customer.GetType().GetProperties()) { customerToBeUpdated.GetType().GetProperty(property.Name). SetValue(customerToBeUpdated, property.GetValue(customer, new object[] { }), new object[] {}); } model.SaveChanges(); }
public void AddCustomer(Customer customer) { Customers.Add(customer); NorthwindEntities model = new NorthwindEntities(); NorthwindDAL.Customer customerToBeInserted = new NorthwindDAL.Customer(); var customerID = (from cust in model.Customers where cust.CustomerID == customer.CustomerID select cust).FirstOrDefault(); if (customerID != null) { return; } foreach (PropertyInfo property in customer.GetType().GetProperties()) { customerToBeInserted.GetType().GetProperty(property.Name). SetValue(customerToBeInserted, property.GetValue(customer, new object[] { }), new object[] { }); } model.Customers.AddObject(customerToBeInserted); model.SaveChanges(); }
public void DeleteCustomer(Customer customer) { Customers.Remove(customer); NorthwindEntities model = new NorthwindEntities(); var custToBeDeleted = (from cust in model.Customers where cust.CustomerID == customer.CustomerID select cust).FirstOrDefault(); model.Customers.DeleteObject(custToBeDeleted); model.SaveChanges(); }