public static string InsertNewCustomer(Customer customer) { if (customer == null) { throw new ArgumentNullException("Customer cannot be null"); } using (var northwindEntities = new NorthwindEntities()) { northwindEntities.Customers.Add(customer); northwindEntities.SaveChanges(); return customer.CustomerID; } }
public static void Main() { var testCustomer = new Customer { CustomerID = "aaa", CompanyName = "Telerik" }; Console.WriteLine("Inserting a new Customer with Id {0} : ", testCustomer.CustomerID); Console.WriteLine(new string('-', 30)); TestInsertingCustomer(testCustomer); Console.WriteLine(); Console.WriteLine("Modifying Customer's Company {0} : ", testCustomer.CompanyName); Console.WriteLine(new string('-', 30)); TestMoodifyingCustomer(testCustomer.CustomerID); Console.WriteLine(); Console.WriteLine("Deleting Customer with Id {0} : ", testCustomer.CustomerID); Console.WriteLine(new string('-', 30)); TestDeleteingCustomer(testCustomer.CustomerID); Console.WriteLine(); var northwindDb = new NorthwindEntities(); Console.WriteLine("Displaying Customers who shipped to Canada in 1997: "); Console.WriteLine(new string('-', 30)); FindCustomersByOrdersYearAndCountry(northwindDb, 1997, "Canada"); Console.WriteLine(); Console.WriteLine("Displaying Customers who shipped to Canada in 1997 (with native SQL): "); Console.WriteLine(new string('-', 30)); FindCustomersByOrdersYearAndCountryWithNativeSql(northwindDb, 1997, "Canada"); Console.WriteLine(); Console.WriteLine("Displaying Orders shipped to Rio de Janeiro between 15 and 20 years ago."); Console.WriteLine(new string('-', 30)); FindSalesByRegionAndTimePeriod(northwindDb, "RJ", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-15)); Console.WriteLine(); }
public static string AddCustomer(string customerId, string companyName, string contactName, string contactTitle, string address, string city, string region, string postalCode, string country, string phone, string fax) { var northwind = new NorthwindEntities(); var customer = new Customer() { CustomerID = customerId, CompanyName = companyName, ContactName = contactName, ContactTitle = contactTitle, Address = address, City = city, Region = region, PostalCode = postalCode, Country = country, Phone = phone, Fax = fax, }; northwind.Customers.Add(customer); northwind.SaveChanges(); return customer.CustomerID; }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="customerID">Initial value of the CustomerID property.</param> /// <param name="companyName">Initial value of the CompanyName property.</param> public static Customer CreateCustomer(global::System.String customerID, global::System.String companyName) { Customer customer = new Customer(); customer.CustomerID = customerID; customer.CompanyName = companyName; return customer; }
// task 2 - Create a DAO class with static methods which provide functionality for inserting, modifying and deleting customers. Write a testing class. private static void TestInsertingCustomer(Customer newCustomer) { var newId = CustomerModifier.InsertNewCustomer(newCustomer); Console.WriteLine("Added a new customer with id {0}", newId); }