public static void ImportFixedData(string path) { //var excelFile = new ExcelQueryFactory(path) { TrimSpaces = TrimSpacesType.Both, ReadOnly = true }; //foreach (var row in excelFile.GetWorksheetNames() // .Select(worksheet => (from row in excelFile.Worksheet(worksheet) select row)).SelectMany(rows => rows)) { using (var ds = FillDataSet(path)) { for (var i = 1; i < ds.Tables[0].Rows.Count; i++) { using (var db = new SqLiteDbContext()) { var local = ds.Tables[0].Rows[i][1].ToString(); switch (local) { case "Klub": var club = new Club(); SetCommonData(club, ds.Tables[0].Rows[i], db); SetClubData(club, ds.Tables[0].Rows[i], db); db.Clubs.AddOrUpdate(x => x.Code, club); break; case "Pub": var pub = new Pub(); SetCommonData(pub, ds.Tables[0].Rows[i], db); SetPubData(pub, ds.Tables[0].Rows[i], db); db.Pubs.AddOrUpdate(x => x.Code, pub); break; case "Restaurant": var restaurant = new Restaurant(); SetCommonData(restaurant, ds.Tables[0].Rows[i], db); SetRestaurantData(restaurant, ds.Tables[0].Rows[i], db); db.Restaurants.AddOrUpdate(x => x.Code, restaurant); break; case "Kawiarnie": var café = new Cafe(); SetCommonData(café, ds.Tables[0].Rows[i], db); SetCaféData(café, ds.Tables[0].Rows[i], db); db.Cafes.AddOrUpdate(x => x.Code, café); break; case "Hotel": var hotel = new Hotel(); SetCommonData(hotel, ds.Tables[0].Rows[i], db); SetHotelData(hotel, ds.Tables[0].Rows[i], db); db.Hotels.AddOrUpdate(x => x.Code, hotel); break; } db.SaveChanges(); } } } } }
private static void SetHotelData(Hotel hotel, DataRow row, SqLiteDbContext db) { hotel.AvailableCoupons = row[33].ToString().ToLower().Equals("yes"); string price = row[59].ToString(); var hotelPrice = db.Prices.FirstOrDefault(x => x.Name.Equals(price)); if (hotelPrice != null) { var hotelPriceId = hotelPrice.Id; hotel.HotelPriceId = hotelPriceId; } else hotel.HotelPrice = new Price {Name = price}; hotel.Checkin = row[60].ToString(); hotel.Checkout = row[61].ToString(); hotel.Opinion = double.Parse(row[62].ToString()); hotel.RoomPrice = uint.Parse(row[63].ToString()); hotel.Stars = uint.Parse(row[64].ToString()); hotel.Parking = row[65].ToString().ToLower().Equals("for free") ? 0 : DoubleValue(row[65].ToString()); hotel.Internet = row[66].ToString().ToLower().Equals("for free") ? 0 : DoubleValue(row[66].ToString()); hotel.Kid = row[67].ToString(); hotel.Animals = row[68].ToString().ToLower().Equals("accepted"); hotel.PicturesLink = row[69].ToString(); }