private static CreditRisk MakeCustomerARisk(Customer customer)
        {
            using (var context = new AutoLotEntities())
            {
                context.Customers.Attach(customer);
                context.Customers.Remove(customer);
                var creditRisk = new CreditRisk()
                {
                    FirstName = customer.FirstName,
                    LastName  = customer.LastName
                };
                context.CreditRisks.Add(creditRisk);
                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    WriteLine(ex);
                }
                catch (Exception ex)
                {
                    WriteLine(ex);
                }

                return(creditRisk);
            }
        }
Beispiel #2
0
 private static void PrintAllInventory()
 {
     using (AutoLotEntities context = new AutoLotEntities())
     {
         foreach (Car item in context.Cars)
         {
             Console.WriteLine(item);
         }
     }
 }
 private static void ShowAllOrdersEagerlyFetched()
 {
     using (var context = new AutoLotEntities())
     {
         WriteLine("*********** Pending Orders ***********");
         var orders = context.Orders
                      .Include(x => x.Customer)
                      .Include(y => y.Car)
                      .ToList();
         foreach (var itm in orders)
         {
             WriteLine($"-> {itm.Customer.FullName} is waiting on {itm.Car.Name}");
         }
     }
 }
Beispiel #4
0
        private static void UpdateRecord()
        {
            // Find a car to delete by primary key.
            using (AutoLotEntities context = new AutoLotEntities())
            {
                Car carToUpdate = (from c in context.Cars
                                   where c.CarID == 2222
                                   select c).FirstOrDefault();

                if (carToUpdate != null)
                {
                    carToUpdate.Color = "Blue";
                    context.SaveChanges();
                }
            }
        }
Beispiel #5
0
 private static void AddNewRecord()
 {
     // Add record to the Inventory table of the AutoLot
     // database.
     using (AutoLotEntities context = new AutoLotEntities())
     {
         try
         {
             // Hard-code data for a new record, for testing.
             context.Cars.Add(new Car()
             {
                 CarID = 2222,
                 Make  = "Yugo",
                 Color = "Brown"
             });
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.InnerException.Message);
         }
     }
 }