public static string InsertCustomer(string customerId, string companyName) { NorthwindEntities context = new NorthwindEntities(); Customer customer = new Customer { CustomerID = customerId, CompanyName = companyName }; context.Customers.Add(customer); context.SaveChanges(); return customerId; }
static void Main(string[] args) { DAOCustomer.InsertCustomer("QWE", "QWERTY"); Customer customer = new Customer { CustomerID = "QWE", CompanyName = "QWERTY", ContactName = "Someone", ContactTitle = "Manager", Address = "Home", City = "Murica", Region = "Earth", PostalCode = "1234", Country = "Murica", Phone = "555-murica-555", Fax = "not using" }; DAOCustomer.UpdateCustomer("QWE", customer); DAOCustomer.DeleteCustomer("QWE"); }
public static void UpdateCustomer(string customerId, Customer newCustomer) { NorthwindEntities context = new NorthwindEntities(); Customer customer = context.Customers.Where(x => x.CustomerID == customerId).FirstOrDefault(); if (customer == null) { throw new ArgumentNullException("The customer you are looking for does not exist!"); } customer.Address = newCustomer.Address; customer.City = newCustomer.City; customer.CompanyName = newCustomer.CompanyName; customer.ContactName = newCustomer.ContactName; customer.ContactTitle = newCustomer.ContactTitle; customer.Country = newCustomer.Country; customer.Fax = newCustomer.Fax; customer.Phone = newCustomer.Phone; customer.PostalCode = newCustomer.PostalCode; customer.Region = newCustomer.Region; context.SaveChanges(); }