Example #1
0
 public static void UpdateCustomer(string companyName, string updateCompanyName)
 {
     using (var db = new NorthwindEntities())
     {
         Customer updateCustomer = GetCustomerCompanyName(db, companyName);
         updateCustomer.CompanyName = updateCompanyName;
         db.SaveChanges();
     }
 }
Example #2
0
 public static void DeleteCustomer(string companyName)
 {
     using (var db = new NorthwindEntities())
     {
         Customer deleteCustomer = GetCustomerCompanyName(db, companyName);
         db.Customers.Remove(deleteCustomer);
         db.SaveChanges();
     }
 }
Example #3
0
 public static void CreateCustomer(string id, string companyName)
 {
     using (var db = new NorthwindEntities())
     {
         Customer newCustomer = new Customer
         {
             CustomerID = id,
             CompanyName = companyName
         };
         db.Customers.Add(newCustomer);
         db.SaveChanges();
     }
 }
Example #4
0
 public static void FindCustomersWithOrders(string shipedCountry, int year)
 {
     using (var db = new NorthwindEntities())
     {
         var orders =
             from o in db.Orders
             where o.Customer.Country == shipedCountry
             select o;
         foreach(var item in orders.Where(x => x.OrderDate.Value.Year == year))
         {
             Console.WriteLine("Company name: {1} --- Order Dates: {0}",
          item.OrderDate.Value.ToShortDateString(), item.Customer.CompanyName);
         }
     }
 }
Example #5
0
 static Customer GetCustomerCompanyName(NorthwindEntities nortwindEntities, string companyName)
 {
     var result = nortwindEntities.Customers.First(
                  x => x.CompanyName == companyName);
         return result;
 }