Esempio n. 1
0
        public async Task SeedContinentStats()
        {
            foreach (var cont in _context.Continent.Include(cs => cs.Stats).ToList())
            {
                var countryCount = await GetTotlCountryNumberForContinentName(cont.Name);

                if (cont.Stats == null)
                {
                    var newStats = new ContinentStats()
                    {
                        CountryCount = countryCount, ContinentId = cont.Id
                    };
                    cont.Stats = newStats;

                    await _context.SaveChangesAsync();
                }
                else if (cont.Stats.CountryCount != countryCount)
                {
                    cont.Stats.CountryCount = countryCount;
                    await _context.SaveChangesAsync();
                }
            }
        }
Esempio n. 2
0
        public async Task Seed(string recreateDbOption)
        {
            if (recreateDbOption != "True")
            {
                return;
            }
            _context.Database.EnsureDeleted();
            _context.Database.Migrate();

            SeedCountries();
            SeedWroldHeritage();

            var user1 = new TUser()
            {
                Id = "fec0a4d6-5830-4eb8-8024-272bd5d6d2bb", UserName = "******"
            };
            var user2 = new TUser()
            {
                Id = "c3b7f625-c07f-4d7d-9be1-ddff8ff93b4d", UserName = "******"
            };


            var country1         = _context.Country.Where(c => c.Alpha3Code == "AZE").FirstOrDefault();
            var country2         = _context.Country.Where(c => c.Alpha3Code == "MEX").FirstOrDefault();
            var countryThailand  = _context.Country.Where(c => c.Alpha3Code == "THA").FirstOrDefault();
            var countryCambodia  = _context.Country.Where(c => c.Alpha3Code == "KHM").FirstOrDefault();
            var countryVietnam   = _context.Country.Where(c => c.Alpha3Code == "VNM").FirstOrDefault();
            var countryUK        = _context.Country.Where(c => c.Alpha3Code == "GBR").FirstOrDefault();
            var countryIndia     = _context.Country.Where(c => c.Alpha3Code == "IND").FirstOrDefault();
            var countryCaboVerde = _context.Country.Where(c => c.Alpha3Code == "CPV").FirstOrDefault();

            _context.TripType.AddRange(
                new TripType()
            {
                TripTypeName = "Real Trip"
            },
                new TripType()
            {
                TripTypeName = "Business Trip"
            },
                new TripType()
            {
                TripTypeName = "Just Visit"
            },
                new TripType()
            {
                TripTypeName = "Only Transfer"
            });

            await _context.SaveChangesAsync();

            _context.UserCountryAssessment.AddRange(
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 30,
                Country              = countryThailand,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 70,
                Country              = countryCambodia,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 40,
                Country              = countryVietnam,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 90,
                Country              = country1,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 60,
                Country              = country2,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 60,
                Country              = countryUK,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.BussinessTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 30,
                Country              = countryIndia,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            },
                new UserCountryAssessment()
            {
                TUser = user1,
                AreaLevelAssessment  = 60,
                Country              = countryCaboVerde,
                CountryKnowledgeType = UserCountryAssessment.CountryVisitType.RealTrip
            }

                );

            await _context.SaveChangesAsync();

            var locationTypeDrink = new LocationType()
            {
                Name = LocationType.LocType.Drink
            };
            var locationTypeWonderOdWorld = new LocationType()
            {
                Name = LocationType.LocType.WonderOfWorld
            };

            var location1 = new Location()
            {
                Name = "Location 1", CreatedBy = "system", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 1", Country = country1, LocationType = locationTypeDrink
            };
            var location2 = new Location()
            {
                Name = "Location 2", CreatedBy = "system", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 2", Country = country1, LocationType = locationTypeWonderOdWorld
            };
            var location3 = new Location()
            {
                Name = "Location 3", CreatedBy = "system", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 3", Country = country2, LocationType = locationTypeWonderOdWorld
            };
            var location4 = new Location()
            {
                Name = "Location 4", CreatedBy = "system", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 4", Country = country2, LocationType = locationTypeDrink
            };

            _context.Trip.AddRange(
                new Trip()
            {
                Name      = "My First Asian Trip",
                CreatedBy = "system",
                Stops     = new List <Stop>()
                {
                    new Stop()
                    {
                        CreatedBy = "system",
                        Location  = new Location()
                        {
                            Country      = countryThailand,
                            CreatedBy    = "system",
                            Latitude     = 13.75,
                            Longitude    = 100.516667,
                            Name         = "Tai Hotel",
                            Description  = "Hotel on Bankgok superb",
                            LocationType = locationTypeDrink
                        },
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 1,
                        StopDescription = "Hotel on Bankgok superb",
                        StopName        = "Tai Hotel"
                    },
                    new Stop()
                    {
                        CreatedBy = "system",
                        Location  = new Location()
                        {
                            Country      = countryCambodia,
                            CreatedBy    = "system",
                            Latitude     = 13.75,
                            Longitude    = 100.516667,
                            Name         = "Angkor Wat",
                            Description  = "Angkor Wat",
                            LocationType = locationTypeWonderOdWorld
                        },
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 2,
                        StopDescription = "Stop Description 2",
                        StopName        = "Stop 2"
                    },
                    new Stop()
                    {
                        CreatedBy = "system",
                        Location  = new Location()
                        {
                            Country      = countryVietnam,
                            CreatedBy    = "system",
                            Latitude     = 13.75,
                            Longitude    = 100.516667,
                            Name         = "Cho Chi Min",
                            Description  = "Cho Chi Min",
                            LocationType = locationTypeWonderOdWorld
                        },
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 2,
                        StopDescription = "Stop Description 2",
                        StopName        = "Stop 2"
                    }
                },
                UserTrips = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = user1, IsOrganiser = true
                    },
                    new UserTrip()
                    {
                        TUser = user2, IsOrganiser = false
                    }
                }
            },
                new Trip()
            {
                Name      = "Trip 2",
                CreatedBy = "system",
                Stops     = new List <Stop>()
                {
                    new Stop()
                    {
                        CreatedBy       = "system",
                        Location        = location2,
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 1,
                        StopDescription = "Stop Description 1",
                        StopName        = "Stop 1"
                    },
                    new Stop()
                    {
                        CreatedBy       = "system",
                        Location        = location4,
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 2,
                        StopDescription = "Stop Description 2",
                        StopName        = "Stop 2"
                    }
                },
                UserTrips = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = user1, IsOrganiser = true
                    },
                    new UserTrip()
                    {
                        TUser = user2, IsOrganiser = false
                    }
                }
            },
                new Trip()
            {
                Name      = "Trip 3",
                CreatedBy = "system",
                Stops     = new List <Stop>()
                {
                    new Stop()
                    {
                        CreatedBy       = "system",
                        Location        = location1,
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 1,
                        StopDescription = "Stop Description 1",
                        StopName        = "Stop 1"
                    },
                    new Stop()
                    {
                        CreatedBy       = "system",
                        Location        = location2,
                        Departure       = DateTime.Today.AddDays(10),
                        Arrival         = DateTime.Today.AddDays(5),
                        Order           = 2,
                        StopDescription = "Stop Description 2",
                        StopName        = "Stop 2"
                    }
                },
                UserTrips = new List <UserTrip>()
                {
                    new UserTrip()
                    {
                        TUser = user1, IsOrganiser = true
                    },
                    new UserTrip()
                    {
                        TUser = user2, IsOrganiser = false
                    }
                }
            }
                );
            await _context.SaveChangesAsync();
        }