Esempio n. 1
0
        public static void SeedData(RentalCarsContext context)
        {
            Console.WriteLine("Applying migrations");
            context.Database.Migrate();

            if (!context.Rentals.Any())
            {
                Console.WriteLine("Adding data - retnals - seeeding");

                var rental = new Rental
                {
                    Name          = "OX-RENTAL",
                    RentalAddress = new Address {
                        City = "WARSAW", Street = "MAZOWIECKA", Number = 1
                    }
                };

                context.Rentals.Add(rental);
                context.SaveChanges();
            }

            if (!context.RentalCars.Any())
            {
                Console.WriteLine("Adding data - cars - seeeding");

                var retnalId = context.Rentals.FirstOrDefault();
                var car1     = new RentalCar
                {
                    Brand          = "BMW",
                    ModelName      = "M3",
                    EngineCapacity = 2.5f,
                    Mileage        = 167000,
                    ProductionYear = 2004,
                    VinNumber      = "EAS42RWE32123",
                    BaseRentCost   = 256,
                    RentalId       = retnalId?.Id ?? 0
                };

                var car2 = new RentalCar
                {
                    Brand          = "FORD",
                    ModelName      = "FOCUS",
                    EngineCapacity = 1.9f,
                    Mileage        = 127000,
                    ProductionYear = 2006,
                    VinNumber      = "EWS42RWE321T6",
                    BaseRentCost   = 152,
                    RentalId       = retnalId?.Id ?? 0
                };

                context.RentalCars.AddRange(car1, car2);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 public CustomerRepo(RentalCarsContext context)
 {
     _context = context;
 }
Esempio n. 3
0
 public RentalCarRepo(RentalCarsContext context)
 {
     _context = context;
 }