public static void addRestaurantToMySQLDB(DisneyRestaurant restaurant) { string connStr = "server=localhost;user=root;port=3306;password=password;database=disneyrestaurants"; using (MySqlConnection conn = new MySqlConnection(connStr)) { try { Console.WriteLine("Connecting to MySQL..."); conn.Open(); String query = "INSERT INTO restaurants (id, restaurant_name, restaurant_url, restaurant_type, location, price_range) VALUES (\"" + restaurant.Id + "\", \"" + restaurant.RestaurantName + "\", \"" + restaurant.RestaurantUrl + "\", \"" + restaurant.RestaurantType + "\",\"" + restaurant.Location + "\", \"" + restaurant.PriceRange + "\");"; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = query; cmd.Connection = conn; cmd.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public void populateDisneyRestaurants(AuthToken token) { this.DisneyRestaurants = new List<DisneyRestaurant>(); foreach (String url in this._restaurantUrls) { DisneyRestaurant restaurant = new DisneyRestaurant(); restaurant.RestaurantUrl = url; DisneyGetRequest restaurantRequest = new DisneyGetRequest(url, token); try { //Location JObject response = JObject.Parse(restaurantRequest.ResponseMessage); JObject links = (JObject)response.SelectToken("links"); JObject ancestorPark = (JObject)links.SelectToken("ancestorThemePark") ?? (JObject)links.SelectToken("ancestorEntertainmentVenue") ?? (JObject)links.SelectToken("ancestorResort"); restaurant.Location = (String)ancestorPark.SelectToken("title"); Console.WriteLine(restaurant.Location); //ID String id = (String)response.SelectToken("id"); String[] words = id.Split(';'); restaurant.Id = Convert.ToInt32(words[0]); Console.WriteLine(restaurant.Id); //Name restaurant.RestaurantName = (String)response.SelectToken("name"); Console.WriteLine(restaurant.RestaurantName); //Price Range JObject facets = (JObject)response.SelectToken("facets"); JArray priceRange = (JArray)facets.SelectToken("priceRange"); restaurant.PriceRange = (String)priceRange[0].SelectToken("urlFriendlyId"); Console.WriteLine(restaurant.PriceRange); // Type of restaurant -- Table or Quick JArray service = (JArray)facets.SelectToken("tableService"); String diningType = null; if (service != null) { JArray tableDiningMealTimesArray = (JArray)facets.SelectToken("dining"); diningType = "Table Service"; } else { service = (JArray)facets.SelectToken("quickService"); if (service != null) { diningType = "Quick Service"; } } restaurant.RestaurantType = diningType; Console.WriteLine(restaurant.RestaurantType); } catch(NullReferenceException err) { Console.WriteLine(err.Message); } if (restaurant.Id != 0) { this.DisneyRestaurants.Add(restaurant); Console.WriteLine("Added restaurant!"); } } }