public void LoadPages() { CatalogPage listPage = new CatalogPage(htmlWeb.Load(HOMEPAGE_URL)); Repository.Clean(); var prevPageNumber = 0; while (listPage.PageNumber > prevPageNumber) { foreach (var link in listPage.Rides) { RidePage ridePage = new RidePage(htmlWeb.Load(link), link); var index = Repository.AddRide(ridePage); Console.WriteLine($"{index}) " + ridePage.Vehicle.ToString()); } prevPageNumber = listPage.PageNumber; listPage = new CatalogPage(htmlWeb.Load(listPage.NextPage)); } Console.WriteLine("No more pages found. Press any key to exit..."); Console.ReadKey(); }
public int AddRide(RidePage page) { MySqlCommand command = new MySqlCommand(@"INSERT INTO `rides` (`uri`, `price`, `vehicle_brand`, `vehicle_model`, `vehicle_year`, `driver_username`, `driver_uri`) VALUES (@Uri, @Price, @VehicleBrand, @VehicleModel, @VehicleYear, @DriverUsername, @DriverUri);", Connection); command.Parameters.AddWithValue("Uri", page.PageUri.ToString()); command.Parameters.AddWithValue("Price", page.Price); command.Parameters.AddWithValue("VehicleBrand", page.Vehicle.Brand); command.Parameters.AddWithValue("VehicleModel", page.Vehicle.Model); command.Parameters.AddWithValue("VehicleYear", page.Vehicle.Year); command.Parameters.AddWithValue("DriverUsername", page.Driver.Username); command.Parameters.AddWithValue("DriverUri", page.Driver.UserPage.ToString()); command.ExecuteNonQuery(); return((int)command.LastInsertedId); }
public List <RidePage> GetVehicleRides(int page, Vehicle vehicle) { MySqlCommand command = new MySqlCommand($@"SELECT * FROM `rides` WHERE `vehicle_brand` = @vehicle_brand AND `vehicle_model` = @vehicle_model AND `vehicle_year` = @vehicle_year LIMIT 25 OFFSET {page * 25};", Connection); command.Parameters.AddWithValue("vehicle_brand", vehicle.Brand); command.Parameters.AddWithValue("vehicle_model", vehicle.Model); command.Parameters.AddWithValue("vehicle_year", vehicle.Year); var result = command.ExecuteReader(); var rides = new List <RidePage>(); while (result.Read()) { var ride = new RidePage() { Id = result.GetInt32(0), PageUri = new Uri(result.GetString(1)), Price = result.GetString(2), Vehicle = new Vehicle() { Brand = result.GetString(3), Model = result.GetString(4), Year = result.GetInt32(5) }, Driver = new Driver() { Username = result.GetString(6), UserPage = new Uri(result.GetString(7)) } }; rides.Add(ride); } return(rides); }