public static void GenerateBusStations(BusTicketContext context)
        {
            var names = new string[] {
                "North Station",
                "West Station",
                "South Station",
                "East Station",
                "NorthEast Station",
                "NorthWest Station",
                "Central Station"
            };

            var townIds = context.Towns.Select(p => p.Id).ToArray();

            var validBusStations = new List <BusStation>();

            var rnd = new Random();

            for (int i = 0; i < names.Length; i++)
            {
                var townsIndex = rnd.Next(0, townIds.Length - 1);

                var busStation = new BusStation
                {
                    Name   = names[i],
                    TownId = townIds[townsIndex]
                };

                validBusStations.Add(busStation);
            }

            context.AddRange(validBusStations);
            context.SaveChanges();
        }
        public static void GenerateCustomers(BusTicketContext context)
        {
            var firstNames = new string[] {
                "Dale",
                "Laura",
                "Dominic",
                "Gordon",
                "Diane",
                "Donna",
                "Audrey",
                "Ben",
                "Marty"
            };

            var lastNames = new string[]
            {
                "Cole",
                "Cooper",
                "Hart",
                "West",
                "Bell",
                "McNulty",
                "Horne",
                "Palmer"
            };

            var validCustomers = new List <Customer>();
            var rnd            = new Random();


            for (int i = 0; i < firstNames.Length; i++)
            {
                var lastNameIndex = rnd.Next(0, lastNames.Length - 1);

                var daysToSubtract = rnd.Next(1000, 10000);

                var customer = new Customer
                {
                    FirstName = firstNames[i],
                    LastName  = lastNames[lastNameIndex],
                    BirthDate = DateTime.Now.AddDays(daysToSubtract * -1),
                    Gender    = (Gender)(i % 3)
                };


                validCustomers.Add(customer);
            }

            context.AddRange(validCustomers);
            context.SaveChanges();
        }
예제 #3
0
        public static void GenerateTickets(BusTicketContext context)
        {
            var seats = new string[] {
                "A1",
                "A2",
                "A3",
                "A4",
                "A5",
                "B1",
                "B2",
                "B3",
                "B4",
                "B5"
            };

            var customerIds = context.Customers.Select(p => p.Id).ToArray();
            var tripIds     = context.Trips.Select(p => p.Id).ToArray();

            var rnd = new Random();

            var validTickets = new List <Ticket>();

            for (int i = 0; i < seats.Length; i++)
            {
                var     customerIndex = rnd.Next(0, customerIds.Length - 1);
                var     tripIndex     = rnd.Next(0, tripIds.Length - 1);
                decimal price         = rnd.Next(10, 20) / (decimal)rnd.Next(1, 5);

                var ticket = new Ticket
                {
                    Seat       = seats[i],
                    CustomerId = customerIds[customerIndex],
                    TripId     = tripIds[tripIndex],
                    Price      = price
                };

                validTickets.Add(ticket);
            }

            context.AddRange(validTickets);
            context.SaveChanges();
        }
        public static void GenerateTowns(BusTicketContext context)
        {
            string[] townNames = new string[]
            {
                "Longdale",
                "StringDale",
                "SpringField",
                "Lodingdon",
                "AppleTown",
                "GeorgeTown",
                "Misty Lake"
            };


            string[] countries = new string[]
            {
                "Zemlemoria",
                "Middle Earch",
                "The green Kingdom",
                "Westeros"
            };


            var validTowns = new List <Town>();
            var rnd        = new Random();

            for (int i = 0; i < townNames.Length; i++)
            {
                int countryIndex = rnd.Next(0, countries.Length - 1);

                var town = new Town()
                {
                    Name    = townNames[i],
                    Country = countries[countryIndex]
                };

                validTowns.Add(town);
            }

            context.AddRange(validTowns);
            context.SaveChanges();
        }
예제 #5
0
        public static void GenerateReview(BusTicketContext context)
        {
            var content = new string[] {
                "good",
                "bad",
                "very good",
                "very bad",
                "Excellent",
                "Appaling",
                "Shockingly bad"
            };


            var validReviews = new List <Review>();

            var companyIds  = context.BusCompanies.Select(p => p.Id).ToArray();
            var customerIds = context.Customers.Select(p => p.Id).ToArray();

            var rnd = new Random();

            for (int i = 0; i < 5; i++)
            {
                var reviewIndex   = rnd.Next(0, content.Length - 1);
                var companyIndex  = rnd.Next(0, companyIds.Length - 1);
                var customerIndex = rnd.Next(0, customerIds.Length - 1);
                var grade         = rnd.Next(0, 10) / rnd.Next(1, 5);

                var review = new Review
                {
                    Content          = content[reviewIndex],
                    Grade            = grade,
                    CustomerId       = customerIds[customerIndex],
                    DateOfPublishing = DateTime.Now,
                    BusCompanyId     = companyIds[companyIndex]
                };

                validReviews.Add(review);
            }

            context.AddRange(validReviews);
            context.SaveChanges();
        }
예제 #6
0
        public static void GenerateCompaines(BusTicketContext context)
        {
            var busCompanyNames = new string[] {
                "UnionIvkoni",
                "UnionDimitrovi",
                "BussesAreUs",
                "DestinationFantasia"
            };


            var nationality = new string[] {
                "Bulgarian",
                "English",
                "French",
                "German",
                "Danish"
            };

            var rnd = new Random();

            var validCompanies = new List <BusCompany>();


            for (int i = 0; i < busCompanyNames.Length; i++)
            {
                var    nationalityIndex = rnd.Next(0, nationality.Length - 1);
                double rating           = rnd.Next(0, 10) / (double)rnd.Next(1, 5);

                var company = new BusCompany
                {
                    Name        = busCompanyNames[i],
                    Nationality = nationality[nationalityIndex],
                    Rating      = rating
                };

                validCompanies.Add(company);
            }

            context.AddRange(validCompanies);
            context.SaveChanges();
        }
예제 #7
0
        public static void GenerateTrips(BusTicketContext context)
        {
            var rnd = new Random();

            var stationIds = context.BusStations.Select(p => p.Id).ToArray();

            var companyIds = context.BusCompanies.Select(p => p.Id).ToArray();

            var validTrips = new List <Trip>();


            for (int i = 0; i < 10; i++)
            {
                int indexStation     = rnd.Next(0, stationIds.Length - 1);
                int destinationIndex = rnd.Next(0, stationIds.Length - 1);
                while (indexStation == destinationIndex)
                {
                    destinationIndex = rnd.Next(0, stationIds.Length - 1);
                }

                int companyIndex = rnd.Next(0, companyIds.Length - 1);

                int days = rnd.Next(20, 100);

                var trip = new Trip
                {
                    DepartureTime        = DateTime.Now.AddDays(days * -1),
                    ArrivalTime          = DateTime.Now.AddDays(rnd.Next(1, 20)),
                    OriginStationId      = stationIds[indexStation],
                    DestinationStationId = stationIds[destinationIndex],
                    BusCompanyId         = companyIds[companyIndex],
                    Status = (Status)(i % 4)
                };

                validTrips.Add(trip);
            }

            context.AddRange(validTrips);
            context.SaveChanges();
        }
예제 #8
0
        public static void GenerateBankAccounts(BusTicketContext context)
        {
            string[] accountNumbers = new string[]
            {
                "123343473",
                "343255",
                "34354623423",
                "34354234",
                "3434232434",
                "342377684534"
            };

            var customerIds = context.Customers.Select(p => p.Id).ToArray();

            var validBankAccounts = new List <BankAccount>();

            var rnd = new Random();

            foreach (var id in customerIds)
            {
                var     index   = rnd.Next(0, accountNumbers.Length - 1);
                decimal balance = rnd.Next(100, 100000) / (decimal)rnd.Next(1, 20);

                var bankAccount = new BankAccount
                {
                    AccountNumber = accountNumbers[index],
                    CustomerId    = id,
                    Balance       = balance
                };

                validBankAccounts.Add(bankAccount);
            }

            context.AddRange(validBankAccounts);
            context.SaveChanges();
        }
예제 #9
0
        private static void Seed(BusTicketContext context)
        {
            var towns = new List <Town>()
            {
                new Town()
                {
                    Name    = "Kyustendil",
                    Country = "Bulgaria",
                },
                new Town()
                {
                    Name    = "Sofia",
                    Country = "Bulgaria",
                },
                new Town()
                {
                    Name    = "Blagoevgrad",
                    Country = "Bulgaria",
                },
                new Town()
                {
                    Name    = "Burgas",
                    Country = "Bulgaria",
                },
                new Town()
                {
                    Name    = "Ruse",
                    Country = "Bulgaria",
                },
            };

            context.AddRange(towns);
            context.SaveChanges();

            var customers = new List <Customer>()
            {
                new Customer()
                {
                    FirstName  = "Cool1",
                    LastName   = "Guy1",
                    HomeTownId = 1,
                    Gender     = CustomerGender.Male
                },
                new Customer()
                {
                    FirstName  = "Cool1",
                    LastName   = "Girl1",
                    HomeTownId = 1,
                    Gender     = CustomerGender.Female
                },
                new Customer()
                {
                    FirstName  = "Cool2",
                    LastName   = "Guy2",
                    HomeTownId = 2,
                    Gender     = CustomerGender.Male
                },
                new Customer()
                {
                    FirstName  = "Cool2",
                    LastName   = "Girl2",
                    HomeTownId = 2,
                    Gender     = CustomerGender.Female
                },
                new Customer()
                {
                    FirstName  = "Cool3",
                    LastName   = "Unknown3",
                    HomeTownId = 3,
                    Gender     = CustomerGender.NotSpecified
                },
            };

            context.Customers.AddRange(customers);
            context.SaveChanges();

            var bankAccounts = new List <BankAccount>()
            {
                new BankAccount()
                {
                    AccountNumber = "Us1",
                    Balance       = 100,
                    CustomerId    = 1
                },
                new BankAccount()
                {
                    AccountNumber = "Us2",
                    Balance       = 200,
                    CustomerId    = 2
                },
                new BankAccount()
                {
                    AccountNumber = "Us3",
                    Balance       = 300,
                    CustomerId    = 3
                },
                new BankAccount()
                {
                    AccountNumber = "Us4",
                    Balance       = 400,
                    CustomerId    = 4
                },
                new BankAccount()
                {
                    AccountNumber = "Us5",
                    Balance       = 500,
                    CustomerId    = 5
                },
            };

            context.BankAccounts.AddRange(bankAccounts);
            context.SaveChanges();

            var reviews = new List <Review>()
            {
                new Review()
                {
                    BusCompanyId = 1,
                    Content      = "It was not bad trip",
                    CustomerId   = 1,
                    Grade        = 5.5
                },
                new Review()
                {
                    BusCompanyId = 1,
                    Content      = "It was a bad trip",
                    CustomerId   = 1,
                    Grade        = 2.0
                },
                new Review()
                {
                    BusCompanyId = 1,
                    Content      = "It was very bad trip",
                    CustomerId   = 2,
                    Grade        = 1.5
                },
                new Review()
                {
                    BusCompanyId = 2,
                    Content      = "It was awesome trip",
                    CustomerId   = 2,
                    Grade        = 8.5
                },
                new Review()
                {
                    BusCompanyId = 3,
                    Content      = "It was average trip",
                    CustomerId   = 3,
                    Grade        = 5.5
                },
            };

            context.Reviews.AddRange(reviews);

            var busCompanies = new List <BusCompany>()
            {
                new BusCompany()
                {
                    Name        = "Union",
                    Nationality = "BG",
                },
                new BusCompany()
                {
                    Name        = "Datsi",
                    Nationality = "BG"
                },
                new BusCompany()
                {
                    Name        = "RussianBuses",
                    Nationality = "RS"
                },
                new BusCompany()
                {
                    Name        = "Vodka",
                    Nationality = "RS"
                },
                new BusCompany()
                {
                    Name        = "UnitedLines",
                    Nationality = "US"
                },
            };

            context.BusCompanies.AddRange(busCompanies);
            context.SaveChanges();

            var busComsForRating = context.BusCompanies
                                   .Include(x => x.Reviews)
                                   .ToList();

            foreach (var company in busComsForRating)
            {
                double rating = 0.0d;
                if (company.Reviews.Count > 0)
                {
                    rating = company.Reviews.Average(x => x.Grade);

                    company.Rating = rating;
                }
                else
                {
                    company.Rating = 0.0d;
                }
            }
            context.SaveChanges();

            var busStations = new List <BusStation>()
            {
                new BusStation()
                {
                    Name   = "Kyustendil Centre",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Kyustendil 2",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Sofia Centre",
                    TownId = 2
                },
                new BusStation()
                {
                    Name   = "Sofia 2",
                    TownId = 2
                },
                new BusStation()
                {
                    Name   = "Blagoevgrad Centre",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Blagoevgrad 2",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Burgas Centre",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Burgas 2",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Ruse Centre",
                    TownId = 1
                },
                new BusStation()
                {
                    Name   = "Ruse 2",
                    TownId = 1
                },
            };

            context.BusStations.AddRange(busStations);
            context.SaveChanges();

            var trips = new List <Trip>()
            {
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 08:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 09:00"),
                    BusCompanyId            = 1,
                    OriginBusStationId      = 1,
                    DestinationBusStationId = 4,
                    Status = TripStatus.Arrived
                },
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 08:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 09:00"),
                    BusCompanyId            = 1,
                    OriginBusStationId      = 2,
                    DestinationBusStationId = 1,
                    Status = TripStatus.Arrived
                },
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 09:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 10:00"),
                    BusCompanyId            = 2,
                    OriginBusStationId      = 2,
                    DestinationBusStationId = 4,
                    Status = TripStatus.Delayed
                },
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 09:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 10:00"),
                    BusCompanyId            = 2,
                    OriginBusStationId      = 5,
                    DestinationBusStationId = 1,
                    Status = TripStatus.Delayed
                },
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 10:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 11:00"),
                    BusCompanyId            = 3,
                    OriginBusStationId      = 1,
                    DestinationBusStationId = 7,
                    Status = TripStatus.Cancelled
                },
                new Trip()
                {
                    DepartureTime           = DateTime.Parse("12-10-2017 10:00"),
                    ArrivalTime             = DateTime.Parse("12-10-2017 11:00"),
                    BusCompanyId            = 3,
                    OriginBusStationId      = 7,
                    DestinationBusStationId = 3,
                    Status = TripStatus.Cancelled
                },
            };

            context.Trips.AddRange(trips);
            context.SaveChanges();

            var tickets = new List <Ticket>()
            {
                new Ticket()
                {
                    CustomerId = 1,
                    Price      = 10.00m,
                    Seat       = "A1",
                    TripId     = 1
                },
                new Ticket()
                {
                    CustomerId = 2,
                    Price      = 10.00m,
                    Seat       = "A2",
                    TripId     = 1
                },
                new Ticket()
                {
                    CustomerId = 3,
                    Price      = 10.00m,
                    Seat       = "B1",
                    TripId     = 2
                },
                new Ticket()
                {
                    CustomerId = 4,
                    Price      = 10.00m,
                    Seat       = "B2",
                    TripId     = 2
                },
                new Ticket()
                {
                    CustomerId = 5,
                    Price      = 10.00m,
                    Seat       = "C5",
                    TripId     = 3
                },
            };

            context.Tickets.AddRange(tickets);
            context.SaveChanges();
        }