public static void Seed(HotelsDbContext db)
        {
            bool alreadySeeded = db.Cities.Any();

            if (alreadySeeded)
            {
                return;
            }

            var servicesGenerator = new ServicesGenerator();
            var citiesGenerator   = new CitiesGenerator();
            var hotelsGenerator   = new HotelsGenerator();
            var reviewGenerator   = new ReviewGenerator();

            // Seed services
            var hotelServices = servicesGenerator.GetAllHotelServices();

            foreach (var service in hotelServices)
            {
                db.HotelServices.Add(service);
            }
            db.SaveChanges();

            // Seed services
            var roomServices = servicesGenerator.GetRoomServices();

            foreach (var service in roomServices)
            {
                db.RoomServices.Add(service);
            }
            db.SaveChanges();

            // Seed citites
            var cities = citiesGenerator.GetCities();

            cities.ForEach(city => db.Cities.Add(city));
            db.SaveChanges();

            var hotels = hotelsGenerator.GetHotels(cities);

            hotels.ForEach(hotel => db.Hotels.Add(hotel));
            db.SaveChanges();

            var reviews = reviewGenerator.GetReviews(hotels);

            reviews.ForEach(review => db.Reviews.Add(review));
            db.SaveChanges();
        }
示例#2
0
        public List <Hotel> GetHotels(IEnumerable <City> cities, int hotelsPerCity = 3)
        {
            var pointGenerator     = new GeoPointGenerator();
            var hotelNameGenerator = new HotelMetadataGenerator();
            var addressGenerator   = new AddressGenerator();
            var cityGenerator      = new CitiesGenerator();
            var servicesGenerator  = new ServicesGenerator();
            var hotels             = new List <Hotel>();

            foreach (var city in cities)
            {
                var hotelTypes = cityGenerator.GetHotelTypesPerCity(city.Id);


                foreach (var hotelType in hotelTypes)
                {
                    var hotelmetadata = hotelNameGenerator.Data.Single(hmd => hmd.HotelType == hotelType);
                    var random        = new Random();
                    var rating        = hotelmetadata.Rating;
                    var location      = pointGenerator.GetClosePoint((city.Latitude, city.Longitude), 1000);
                    var(latitude, longitude) = location;


                    var hotel = new Hotel
                    {
                        Name        = $"{hotelmetadata.Prefix} {city.Name}",
                        Description = $"Is a {rating}-Star luxury hotel located in {city.Name} which was opened in {hotelmetadata.Year}. It has quality rooms and a modern, well equipped conference area which can host events of every kind for up to 100 persons. Its an ideal stopover on your journey. Is set in the heart of the lush is perfect for holiday or business. If you just wish to relax there are many walks, cycle rides or car excursions to local quaint and historical villages and towns in picturesque surroundings. If you don't feel like outdoor exercise you can relax either in our Finnish sauna, bio sauna, infrared sauna, jacuzzi. Or, if your feeling up to it, why not work out gently in the gym. After a relaxing dinner and a quiet drink in our Bistro bar sleep should be no problem in one of our cosy and comfortable rooms. Our young and friendly staff are here to welcome and serve you. Hope to see you soon!",
                        City        = city,
                        Address     = new Address
                        {
                            PostCode = addressGenerator.GetPostCode(),
                            Street   = addressGenerator.GetStreet()
                        },
                        CheckinTime  = new TimeSpan(15, 0, 0),
                        CheckoutTime = new TimeSpan(12, 0, 0),
                        Location     = new Location {
                            Latitude = latitude, Longitude = longitude
                        },
                        Rating    = rating,
                        Visits    = random.Next(10000, 30000),
                        NumPhotos = 1,
                        RoomTypes = new RoomType[] {
                            GetRoomType(hotelmetadata.RoomTypes.single),
                            GetRoomType(hotelmetadata.RoomTypes.@double)
                        },
                        ConferenceRooms = new[]
                        {
                            new ConferenceRoom
                            {
                                Name         = $"{HotelMetadataGenerator.GetConferenceRoomName(hotelType)} room",
                                Rating       = rating,
                                Capacity     = 40,
                                PricePerHour = 190,
                                NumPhotos    = 3
                            }
                        }
                    };
                    hotel.Services = servicesGenerator.GetHotelServicesByHotelType(hotelType)
                                     .Select(hs => new ServicePerHotel()
                    {
                        Service = hs,
                        Hotel   = hotel
                    }).ToList();
                    hotels.Add(hotel);
                }
            }

            return(hotels);
        }