Esempio n. 1
0
        static Car UpdateRandomCar(CarBoundContext context)
        {
            var randomCar = context.Cars.GetRandomElement();

            randomCar.Model += $" (modified {DateTime.Now}";
            context.SaveChanges();
            return(randomCar);
        }
Esempio n. 2
0
        static Car CreateNewCar(CarBoundContext context)
        {
            var newCar = _carFactory.CreateNewRandomCar();

            context.Cars.Add(newCar);
            context.SaveChanges();
            return(newCar);
        }
Esempio n. 3
0
        static void RemoveAllCars(CarBoundContext context)
        {
            var cars  = context.Cars;
            var count = cars.Count();

            cars.RemoveRange(cars);
            context.SaveChanges();
            Console.Clear();
            Console.WriteLine($"Removed {count} cars from repository.");
            PressAnyKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // The database will be created at bin/Debug/ by default
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine("c:\\temp\\", ""));
            // Get a new context for de DB (always "using" to dispose the connection)
            using (var context = new CarBoundContext())
            {
                do
                {
                    switch (ShowMenu(context.Cars.Count()))
                    {
                    case ConsoleKey.D1:
                        var newCar = CreateNewCar(context);
                        ShowNewCar(newCar);
                        break;

                    case ConsoleKey.D2:
                        var cars = GetCars(context);
                        ShowCars(cars);
                        break;

                    case ConsoleKey.D3:
                        var updatedCar = UpdateRandomCar(context);
                        ShowUpdatedCar(updatedCar);
                        break;

                    case ConsoleKey.D4:
                        RemoveAllCars(context);
                        break;

                    case ConsoleKey.D0:
                        return;
                    }

                    Console.Clear();
                } while (true);
            }
        }
Esempio n. 5
0
 static IEnumerable <Car> GetCars(CarBoundContext context)
 {
     return(context.Cars);
 }