public async Task <bool> SaveChangesAsync() { _logger.LogInformation($"Attempitng to save the changes in the context"); // Only return success if at least one row was changed return((await _context.SaveChangesAsync()) > 0); }
private async void SeedInMemoryStore() { SeedCountries(); 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 locationTypeDrink = new LocationType() { Name = LocationType.LocType.Drink }; var locationTypeWonderOdWorld = new LocationType() { Name = LocationType.LocType.WonderOfWorld }; var location1 = new Location() { Name = "Location 1", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 1", Country = country1, LocationType = locationTypeDrink }; var location2 = new Location() { Name = "Location 2", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 2", Country = country1, LocationType = locationTypeWonderOdWorld }; var location3 = new Location() { Name = "Location 3", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 3", Country = country2, LocationType = locationTypeWonderOdWorld }; var location4 = new Location() { Name = "Location 4", Latitude = 5435.4554, Longitude = 4535.6542, Description = "Description 4", Country = country2, LocationType = locationTypeDrink }; _context.Trip.AddRange( new Trip() { Name = "My First Asian Trip", Stops = new List <Stop>() { new Stop() { Location = new Location() { Country = countryThailand, 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() { Location = location3, Departure = DateTime.Today.AddDays(10), Arrival = DateTime.Today.AddDays(5), Order = 2, StopDescription = "Stop Description 2", StopName = "Stop 2" } } }, new Trip() { Name = "Trip 2", Stops = new List <Stop>() { new Stop() { Location = location2, Departure = DateTime.Today.AddDays(10), Arrival = DateTime.Today.AddDays(5), Order = 1, StopDescription = "Stop Description 1", StopName = "Stop 1" }, new Stop() { Location = location4, Departure = DateTime.Today.AddDays(10), Arrival = DateTime.Today.AddDays(5), Order = 2, StopDescription = "Stop Description 2", StopName = "Stop 2" } } }, new Trip() { Name = "Trip 3", Stops = new List <Stop>() { new Stop() { Location = location1, Departure = DateTime.Today.AddDays(10), Arrival = DateTime.Today.AddDays(5), Order = 1, StopDescription = "Stop Description 1", StopName = "Stop 1" }, new Stop() { Location = location2, Departure = DateTime.Today.AddDays(10), Arrival = DateTime.Today.AddDays(5), Order = 2, StopDescription = "Stop Description 2", StopName = "Stop 2" } } } ); await _context.SaveChangesAsync(); }