Exemplo n.º 1
0
 static void SecondScene()
 {
     using (var context = new SceneFourContext())
     {
         Console.WriteLine("Do you want to save a business? (1/0)");
         string ans = Console.ReadLine();
         if (ans.Contains("y"))
         {
             var business = new Business();
             Console.WriteLine("Enter name");
             business.Name = Console.ReadLine();
             Console.WriteLine("Enter License Number");
             business.LicenseNumber = Console.ReadLine();
             context.Businesses.Add(business);
             var retail = new Retail();
             Console.WriteLine("Enter retail name");
             retail.Name = Console.ReadLine();
             Console.WriteLine("Enter retail License Number");
             retail.LicenseNumber = Console.ReadLine();
             Console.WriteLine("Enter retail address");
             retail.Address = Console.ReadLine();
             Console.WriteLine("Enter retail city");
             retail.City = Console.ReadLine();
             Console.WriteLine("Enter retail state");
             retail.State = Console.ReadLine();
             Console.WriteLine("Enter retail ZIPCode");
             retail.ZIPCode = Console.ReadLine();
             context.Businesses.Add(retail);
             var web = new eCommerce();
             Console.WriteLine("Enter eCommerce name");
             web.Name = Console.ReadLine();
             Console.WriteLine("Enter eCommerce License Number");
             web.LicenseNumber = Console.ReadLine();
             Console.WriteLine("Enter eCommerce URL");
             web.URL = Console.ReadLine();
             context.Businesses.Add(web);
             context.SaveChanges();
         }
     }
     using (var context = new SceneFourContext())
     {
         foreach (var b in context.Businesses)
         {
             Console.WriteLine("{0} (#{1})", b.Name, b.LicenseNumber);
         }
         foreach (var r in context.Businesses.OfType <Retail>())
         {
             Console.WriteLine("{0} (#{1})", r.Name, r.LicenseNumber);
             Console.WriteLine("{0}", r.Address);
             Console.WriteLine("{0}, {1} {2}", r.City, r.State, r.ZIPCode);
         }
         foreach (var e in context.Businesses.OfType <eCommerce>())
         {
             Console.WriteLine("{0} (#{1})", e.Name, e.LicenseNumber);
             Console.WriteLine("Online address is: {0}", e.URL);
         }
     }
 }
Exemplo n.º 2
0
 public void Test4()
 {
     using (var context = new HierarchyModel())
     {
         var business = new Business
         {
             Name          = "Corner Dry Cleaning",
             LicenseNumber = "100x1"
         };
         context.Businesses.Add(business);
         var retail = new Retail
         {
             Name          = "Shop and Save",
             LicenseNumber =
                 "200C",
             Address = "101 Main",
             City    = "Anytown",
             State   = "TX",
             ZIPCode = "76106"
         };
         context.Businesses.Add(retail);
         var web = new eCommerce
         {
             Name          = "BuyNow.com",
             LicenseNumber =
                 "300AB",
             URL = "www.buynow.com"
         };
         context.Businesses.Add(web);
         context.SaveChanges();
     }
     using (var context = new HierarchyModel())
     {
         Console.WriteLine("\n--- All Businesses ---");
         foreach (var b in context.Businesses)
         {
             Console.WriteLine("{0} (#{1})", b.Name, b.LicenseNumber);
         }
         Console.WriteLine("\n--- Retail Businesses ---");
         foreach (var r in context.Businesses.OfType <Retail>())
         {
             Console.WriteLine("{0} (#{1})", r.Name, r.LicenseNumber);
             Console.WriteLine("{0}", r.Address);
             Console.WriteLine("{0}, {1} {2}", r.City, r.State, r.ZIPCode);
         }
         Console.WriteLine("\n--- eCommerce Businesses ---");
         foreach (var e in context.Businesses.OfType <eCommerce>())
         {
             Console.WriteLine("{0} (#{1})", e.Name, e.LicenseNumber);
             Console.WriteLine("Online address is: {0}", e.URL);
         }
     }
 }