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(); }
/// <summary> /// Fills the Customer collection with data. /// </summary> private void CreateCustomers() { NorthwindEntities model = new NorthwindEntities(); var customers = from customer in model.Customers select customer; foreach (NorthwindDAL.Customer cust in customers) { Customers.Add(new Customer() { CustomerID = cust.CustomerID, ContactName = cust.ContactName, ContactTitle = cust.ContactTitle, CompanyName = cust.CompanyName }); } }
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(); }