Пример #1
0
        public static void Seed(BusTicketsContext context)
        {
            Town[] towns = TownGenerator.GenerateTowns();
            context.Towns.AddRange(towns);

            BusCompany[] companies = BusCompanyGenerator.GenerateBusCompanies();
            context.BusCompanies.AddRange(companies);

            BusStation[] stations = BusStationGenerator.GenerateBusStations(towns);
            context.BusStations.AddRange(stations);

            Customer[] customers = CustomerGenerator.GenerateCustomers(towns);
            context.Customers.AddRange(customers);

            BankAccount[] accounts = BankAccountGenerator.GenerateBankAccounts(customers);
            context.BankAccounts.AddRange(accounts);

            //BusCompany[] companiesFromDb = context.BusCompanies.ToArray();
            Review[] reviews = ReviewGenerator.GenerateReviews(companies, customers);
            context.Reviews.AddRange(reviews);

            Trip[] trips = TripGenerator.GenerateTrips(stations, companies);
            context.Trips.AddRange(trips);

            Ticket[] tickets = TicketGenerator.GenerateTicket(customers, trips);
            context.Tickets.AddRange(tickets);

            context.SaveChanges();

            Console.WriteLine("Sample data inserted successfully.");
        }
        private static void ResetDatabase()
        {
            using (var db = new BusTicketContext())
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();

                TownGenerator.GenerateTowns(db);
                BusCompanyGenerator.GenerateCompaines(db);
                BusStationGenerator.GenerateBusStations(db);
                CustomerGenerator.GenerateCustomers(db);
                TripGenerator.GenerateTrips(db);
                BankAccountGenerator.GenerateBankAccounts(db);
                ReviewGenerator.GenerateReview(db);
                TicketGenrator.GenerateTickets(db);
            }
        }