public static void AddCustomer(Customer customer) { using (var dbContext = new NorthwindEntities()) { dbContext.Customers.Add(customer); dbContext.SaveChanges(); } }
public static void Insert(Customer customer) { if (customer == null) { throw new ArgumentNullException("Customer cannot be null."); } if (string.IsNullOrWhiteSpace(customer.CustomerID)) { throw new ArgumentException("CustomerID is mandatory."); } using (var dbContext = new NorthwindEntities()) { dbContext.Customers.Add(customer); dbContext.SaveChanges(); } }
static void Main(string[] args) { // TASK 2 var customerToAdd = new Customer() { CustomerID = "ASD", CompanyName = "EF-Company" }; //CustomersManager.AddCustomer(customerToAdd); //CustomersManager.EditCustomerCompanyName("ASD", "NovoIme"); //CustomersManager.DeleteCustomer("ASD"); //// TASK 3 //var customersShippedOrdersToCanadaIn1997 = CustomersManager.GetCustomersByShippmentDateAndCountry( // "Canada", // new DateTime(1997, 1, 1)); //PrintCustomers(customersShippedOrdersToCanadaIn1997); //// TASK 4 //customersShippedOrdersToCanadaIn1997 = CustomersManager // .GetCustomersByShippmentDateAndCountryNative( // "Canada", // new DateTime(1997, 1, 1)); //PrintCustomers(customersShippedOrdersToCanadaIn1997); // TASK 5 var startDate = new DateTime(1997, 01, 01); var endtDate = new DateTime(1997, 04, 30); string region = "WA"; var salesInWAInFirstQuarter1997 = GetSalesByRegionAndDateRange( startDate, endtDate, region); PrintOrders(salesInWAInFirstQuarter1997); // TASK 6 }
private static void InsertModifyDeleteCustomers() { string newCustomerId = "GJDMA"; var newCustomer = new Customer() { CustomerID = newCustomerId, CompanyName = "Google", ContactName = "Jane Doe", City = "Melbourne", Country = "Australia" }; CustomersDAO.Insert(newCustomer); CustomersDAO.Modify(newCustomerId, "Janey Doe"); CustomersDAO.Delete(newCustomerId); }