コード例 #1
0
        public void GenerateReportingForRegionsAndContinents()
        {
            foreach (var continent in _context.Continent.ToList())
            {
                int countriesCountInContinent = 0;

                foreach (var region in _context.Region.Where(r => r.ContinentId == continent.Id).ToList())
                {
                    var countriesCountInRegion = _context.Country.Where(c => c.RegionId == region.Id).Count();
                    region.CountriesCount = countriesCountInRegion;

                    countriesCountInContinent += countriesCountInRegion;
                    _context.SaveChanges();
                }

                continent.CountryCount = countriesCountInContinent;
                _context.SaveChanges();
            }
        }
コード例 #2
0
        private void SeedAirports()
        {
            if (_context.Airport.Any())
            {
                return;
            }

            var airportsFilePath = Path.Combine(AppContext.BaseDirectory, "LoadData\\airports.dat.txt");

            using (var reader = new StreamReader(airportsFilePath))
            {
                var listOfAirports     = new List <Airport>();
                var countriesDictonary = new Dictionary <int, string>();
                foreach (var country in _context.Country.ToList())
                {
                    countriesDictonary.Add(country.Id, country.Name);
                }

                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine().Replace("\"", "");
                    var values = line.Split(',');

                    var airport = new Airport()
                    {
                        AirportId   = values[0],
                        Name        = values[1],
                        City        = values[2],
                        CountryName = values[3],
                        IATA        = values[4],
                        ICAO        = values[5]
                                      //TODO: Fix an convert issue for airport latitude and longitude
                                      //Latitude = Convert.ToInt64(values[6]),
                                      //Longitude = Convert.ToInt64(values[7])
                    };

                    switch (values[3])
                    {
                    case "Reunion":
                        values[3] = "Réunion";
                        break;

                    case "Burma":
                        values[3] = "Myanmar";
                        break;

                    case "Congo (Brazzaville)":
                        values[3] = "DR Congo";
                        break;

                    case "Congo (Kinshasa)":
                        values[3] = "DR Congo";
                        break;

                    case "Czech Republic":
                        values[3] = "Czechia";
                        break;
                    }

                    var countryId = countriesDictonary.Where(c => c.Value == values[3]).Select(c => c.Key).FirstOrDefault();
                    if (countryId != 0)
                    {
                        airport.CountryId = countryId;
                    }

                    listOfAirports.Add(airport);
                }
                _context.AddRange(listOfAirports);
                _context.SaveChanges();
            }
        }
コード例 #3
0
ファイル: MCBDataSeeder.cs プロジェクト: michalstanik/MST.MCB
        public void Seed()
        {
            if (_context.Trip.Any())
            {
                return;
            }

            //Dictonaries
            _createdCountries = _context.Country.ToList();
            _createdAirports  = _context.Airport.ToList();

            //Created in DataSeeder
            _createdUsers             = CreateUsers();
            _createdAirlineAlliances  = CreateAirlineAlliance();
            _createdAirlines          = CreateAirlines();
            _createdAircraftFactories = CreateAircraftFactories();
            _createdAircraftModels    = CreateAircraftModel();
            _createdAircrafts         = CreateAircrafts();
            _createdFlights           = CreateFlights();

            var firstAsiaTrip = new Trip()
            {
                Name              = "My First Asia Trip",
                TripManager       = GetUser("Michał"),
                TripTypeAssesment = Trip.TripType.RealTrip,
                UserTrips         = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = GetUser("Michał")
                    }
                },
                Stops = new List <Stop>()
                {
                    new Stop()
                    {
                        Name        = "Bangok",
                        Description = "First Day in Bangok",
                        Order       = 1,
                        Arrival     = new DateTime(2016, 10, 31),
                        Departure   = new DateTime(2016, 11, 1),
                        Country     = GetCountry("THA"),
                        Latitude    = 00.000000,
                        Longitude   = 00.000000,
                    },
                    new Stop()
                    {
                        Name        = "Cambodia",
                        Description = "First Day in Cambodia",
                        Order       = 1,
                        Arrival     = new DateTime(2016, 11, 2),
                        Departure   = new DateTime(2016, 11, 4),
                        Country     = GetCountry("KHM"),
                        Latitude    = 00.000000,
                        Longitude   = 00.000000,
                    },
                    new Stop()
                    {
                        Name        = "Vietnam",
                        Description = "First Day in Vietnam",
                        Order       = 1,
                        Arrival     = new DateTime(2016, 11, 7),
                        Departure   = new DateTime(2016, 11, 14),
                        Country     = GetCountry("VNM"),
                        Latitude    = 00.000000,
                        Longitude   = 00.000000,
                    }
                },
                Flights = new List <Flight>()
                {
                    new Flight()
                    {
                        DepartureAirport     = _context.Airport.Where(s => s.IATA == "WAW").FirstOrDefault(),
                        ArrivalAirport       = _context.Airport.Where(s => s.IATA == "DXB").FirstOrDefault(),
                        DepartureDate        = new DateTime(2016, 10, 31, 13, 25, 00),
                        ArrivialDate         = new DateTime(2016, 10, 31, 22, 5, 00),
                        FlightNumber         = "EK180",
                        FlightTypeAssessment = Flight.FlightType.Scheduled,
                        UserFlights          = new List <UserFlight>()
                        {
                            new UserFlight()
                            {
                                TUser = GetUser("Michał")
                            }
                        }
                    },
                    new Flight()
                    {
                        DepartureAirport     = _context.Airport.Where(s => s.IATA == "DXB").FirstOrDefault(),
                        ArrivalAirport       = _context.Airport.Where(s => s.IATA == "BKK").FirstOrDefault(),
                        DepartureDate        = new DateTime(2016, 11, 1, 9, 32, 00),
                        ArrivialDate         = new DateTime(2016, 11, 1, 18, 15, 00),
                        FlightNumber         = "EK418",
                        FlightTypeAssessment = Flight.FlightType.Scheduled,
                        UserFlights          = new List <UserFlight>()
                        {
                            new UserFlight()
                            {
                                TUser = GetUser("Michał")
                            }
                        }
                    }
                }
            };

            var azerbaijanTrip = new Trip()
            {
                Name = "My First Azerbaijan Trip",
                TripTypeAssesment = Trip.TripType.RealTrip,
                TripManager       = GetUser("Michał"),
                UserTrips         = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = GetUser("Michał")
                    }
                },
                Stops = new List <Stop>()
                {
                    new Stop()
                    {
                        Name          = "Baku",
                        Description   = "First Day in Baku",
                        Order         = 1,
                        Arrival       = new DateTime(2019, 5, 1),
                        Departure     = new DateTime(2019, 5, 2),
                        Country       = GetCountry("AZE"),
                        Latitude      = 40.383333,
                        Longitude     = 49.866667,
                        WorldHeritage = _context.WorldHeritage.Where(w => w.UnescoId == "1076").FirstOrDefault()
                    },
                    new Stop()
                    {
                        Name          = "Apsheron",
                        Description   = "Second Day in Baku",
                        Order         = 2,
                        Arrival       = new DateTime(2019, 5, 2),
                        Departure     = new DateTime(2019, 5, 3),
                        Country       = GetCountry("AZE"),
                        Latitude      = 40.383333,
                        Longitude     = 49.866667,
                        WorldHeritage = _context.WorldHeritage.Where(w => w.UnescoId == "958").FirstOrDefault()
                    }
                }
            };

            var threeAfricanCountriesTrip = new Trip()
            {
                Name = "Three African Countries Trip",
                TripTypeAssesment = Trip.TripType.RealTrip,
                TripManager       = GetUser("Michał"),
                UserTrips         = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = GetUser("Michał")
                    }
                },
                Stops = new List <Stop>()
                {
                    new Stop()
                    {
                        Name        = "Banjul",
                        Description = "First night in Banjul",
                        Order       = 1,
                        Country     = GetCountry("GMB"),
                        Arrival     = new DateTime(2019, 12, 13),
                        Departure   = new DateTime(2019, 12, 14),
                        Latitude    = 13.466667,
                        Longitude   = -16.6
                    },
                    new Stop()
                    {
                        Name        = "Bubaque",
                        Description = "Archipel des Bijagos, Bubaque Island",
                        Order       = 2,
                        Country     = GetCountry("GNB"),
                        Arrival     = new DateTime(2019, 12, 14),
                        Departure   = new DateTime(2019, 12, 16),
                        Latitude    = 11.283333,
                        Longitude   = -15.833333
                    },
                    new Stop()
                    {
                        Name        = "Cap Skirring",
                        Description = "Cap Skirring",
                        Order       = 3,
                        Country     = GetCountry("SEN"),
                        Arrival     = new DateTime(2019, 12, 17),
                        Departure   = new DateTime(2019, 12, 19),
                        Latitude    = 12.389444,
                        Longitude   = -16.738333
                    }
                }
            };


            _context.AddRange(azerbaijanTrip, firstAsiaTrip, threeAfricanCountriesTrip);
            _context.SaveChanges();

            _context.UserCountry.AddRange(
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 30,
                Country              = GetCountry("THA"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 70,
                Country              = GetCountry("KHM"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 40,
                Country              = GetCountry("VNM"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 90,
                Country              = GetCountry("AZE"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 60,
                Country              = GetCountry("MEX"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 60,
                Country              = GetCountry("GBR"),
                CountryKnowledgeType = UserCountry.CountryVisitType.BussinessTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 30,
                Country              = GetCountry("IND"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 60,
                Country              = GetCountry("CPV"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 40,
                Country              = GetCountry("GMB"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 30,
                Country              = GetCountry("SEN"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            },
                new UserCountry()
            {
                TUser = GetUser("Michał"),
                AreaLevelAssessment  = 60,
                Country              = GetCountry("GNB"),
                CountryKnowledgeType = UserCountry.CountryVisitType.RealTrip
            }
                );

            _context.SaveChanges();
        }
コード例 #4
0
        private async Task SeedCountries()
        {
            //TODO: PROD: Below source should be relative
            using (StreamReader r = new StreamReader("C:/Users/micha/source/repos/MCB/MCB/MCB.Data/LoadData/countries.json"))
            {
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };

                string json = r.ReadToEnd();
                List <CountriesDataModel> items = JsonConvert.DeserializeObject <List <CountriesDataModel> >(json, settings);
                foreach (var item in items)
                {
                    var continent = new Continent();

                    var existingContinent = _context.Continent.Where(c => c.Name == item.region).FirstOrDefault();

                    if (existingContinent == null)
                    {
                        continent = new Continent()
                        {
                            Name = item.region
                        };
                        _context.Add(continent);
                        _context.SaveChanges();
                    }
                    else
                    {
                        continent = existingContinent;
                    }

                    var region         = new Region();
                    var existingRegion = _context.Region.Where(rg => rg.Name == item.subregion).FirstOrDefault();

                    if (existingRegion == null)
                    {
                        region = new Region()
                        {
                            Name = item.subregion, Continent = continent
                        };
                        _context.Add(region);
                        _context.SaveChanges();
                    }
                    else
                    {
                        region = existingRegion;
                    }

                    var newCountry = new Country()
                    {
                        Name         = item.name.common,
                        OfficialName = item.name.official,
                        Alpha2Code   = item.cca2,
                        Alpha3Code   = item.cca3,
                        Area         = item.area,
                        Region       = region
                    };
                    _context.Add(newCountry);
                    await _context.SaveChangesAsync();
                }
            }
        }