public static void Seed(HotelDbContext db) { bool alreadySeeded = db.Citys.Any(); if (alreadySeeded) { return; } var servicesGenerator = new ServicesGenerator(); var citiesGenerator = new CitiesGenerator(); var hotelsGenerator = new HotelsGenerator(); var reviewGenerator = new ReviewGenerator(); // Seed hotel services var hotelServices = servicesGenerator.GetAllHotelService(); foreach (var service in hotelServices) { db.HotelServices.Add(service); } db.SaveChanges(); // Seed room services var roomServices = servicesGenerator.GetRoomServices(); foreach (var service in roomServices) { db.RoomServices.Add(service); } db.SaveChanges(); // Seed cities var cities = citiesGenerator.GetCities(); foreach (var city in cities) { db.Citys.Add(city); } db.SaveChanges(); var hotels = hotelsGenerator.GetHotels(cities); hotels.ForEach(h => db.Hotels.Add(h)); db.SaveChanges(); var reviews = reviewGenerator.GetReviews(hotels); reviews.ForEach(r => db.Reviews.Add(r)); db.SaveChanges(); }
public static void Seed(HotelsDbContext db) { // Проверка на заполненность var alreadySeeded = db.Cities.Any(); if (alreadySeeded) { return; } var servicesGenerator = new ServicesGenerator(); var citiesGenerator = new CitiesGenerator(); var hotelsGenerator = new HotelsGenerator(); var reviewGenerator = new ReviewGenerator(); // Заполняем отельные сервисы var hotelServices = servicesGenerator.GetAllHotelServices(); foreach (var service in hotelServices) { db.HotelServices.Add(service); } db.SaveChanges(); // Заполняем сервисы для номеров var roomServices = servicesGenerator.GetRoomServices(); foreach (var service in roomServices) { db.RoomServices.Add(service); } db.SaveChanges(); // Заполняем города 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(); } // Seed
private RoomType GetRoomType(int type) { var serviceGenerator = new ServicesGenerator(); RoomType room = null; switch (type) { case HotelSeedMetada.ROOMTYPE_SINGLE: room = new RoomType { Name = "Single room", Capacity = 1, Description = "Our single rooms have an area of 26m² with a 1.60m Queen size bed.", Price = 180, NumPhotos = 3, SingleBeds = 1 }; room.Services = serviceGenerator.GetRoomServices() .Select(rs => new ServicePerRoom() { RoomType = room, Service = rs }).ToList(); return(room); case HotelSeedMetada.ROOMTYPE_DOUBLE: room = new RoomType { Name = "Double room", Capacity = 2, Description = "The doubles are 32m² with French Size twin beds of 1.40m", Price = 300, NumPhotos = 4, TwinBeds = 2 }; room.Services = serviceGenerator.GetRoomServices() .Select(rs => new ServicePerRoom() { RoomType = room, Service = rs }).ToList(); return(room); case HotelSeedMetada.ROOMTYPE_DOUBLE2: room = new RoomType { Name = "Double room", Capacity = 2, Description = "The doubles are 40m² with a 3.20m double Queen size bed", Price = 400, NumPhotos = 2, TwinBeds = 2, }; room.Services = serviceGenerator.GetRoomServices() .Select(rs => new ServicePerRoom() { RoomType = room, Service = rs }).ToList(); return(room); case HotelSeedMetada.ROOMTYPE_LUXURY: room = new RoomType { Name = "Luxury room", Capacity = 2, Description = "Luxury room is 42m² with a 3.20m double Queen size bed.", Price = 500, NumPhotos = 3, DoubleBeds = 1, }; room.Services = serviceGenerator.GetRoomServices() .Select(rs => new ServicePerRoom() { RoomType = room, Service = rs }).ToList(); return(room); default: return(null); } }