static async Task pull_product_supplier() { product prod = new product(); foreach (int prod_num in prod.get_raw_products()) { // prod.delete_items(prod_num); // await get_supplier(prod_num); Console.WriteLine("Working Product: " + prod_num); pickup this_pickup = await get_supplier_details(prod_num); } }
static async Task begin_integrate(bool ignore_fail) { //build product matching table product prod = new product(); Hashtable product_lookup = prod.product_lookup(); //build pickup matching table pickup_lookup = prod.pickup_lookup(); //load products to be imported booking bookclass = new booking(); List <booking> bookings = bookclass.get_bookings(ignore_fail); int x = 1; foreach (booking mbook in bookings) { Console.Write(x + ". Migrating Resmark#: " + mbook.res_num + " -> "); x++; if (mbook.available_item().Length > 0) { //item available //assign activity ID string activity_id = mbook.available_item(); //get pickup ID pickup this_pickup = await get_pickup_details(mbook); //does pick up location match?? if (this_pickup != null) { //pickup location found //create cart item string cart_id = await create_cart(); if (cart_id.Length > 0) { //add item to cart return_object cart_return = await add_item_to_cart(activity_id, cart_id, mbook, this_pickup); mbook.update_status(cart_return.return_message, false); //update booking record with response after add item to cart if (cart_return.return_obj != null) //no errors. next step { //Lets add customer details JObject jObject = (JObject)cart_return.return_obj; return_object cart_update_return = await add_customer_info(cart_id, mbook); mbook.update_status(cart_return.return_message, false); //update booking record with response after add customer if (cart_update_return.return_obj != null) //no errors from add customer. next step { return_object create_order_return = await create_order(cart_id, mbook); // create order if (create_order_return.return_obj != null) //no errors from add customer. next step { JObject jobject = (JObject)create_order_return.return_obj; Console.WriteLine("Migration completed > Confirmation: " + (string)(jobject["confirmation"])); mbook.update_status(create_order_return.return_message, true, (string)jobject["id"], Convert.ToInt32(jobject["confirmation"])); //update booking record with response after successful create order } else { Console.WriteLine("Error : " + create_order_return.return_message); mbook.update_status(create_order_return.return_message, false); //update booking record with response after failed create order } } else { //error adding customer to cart Console.WriteLine("Error adding customer info to cart"); mbook.update_status("Error adding customer info to cart", false); } } else { // error adding item to cart Console.WriteLine("Error adding item to cart "); // mbook.update_status("Error adding item to cart", false); } } else { //no cart id returned Console.WriteLine("No cart id returned"); mbook.update_status("No cart id", false); } } //no pickup options found.. what to do next? } //no date available, update booking record else { Console.WriteLine("No available dates found"); mbook.update_status("No available dates", false); } } }
static async Task <pickup> get_pickup_details(booking this_book) { dynamic jsonObj = ""; string ret = ""; pickup pickup_d = new pickup(); string _url = "https://app.resmarksystems.com/public/api/product/" + this_book.product_number + "/pickup"; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = await _client.GetAsync(_url); try { // response.EnsureSuccessStatusCode(); ret = await response.Content.ReadAsStringAsync(); JavaScriptSerializer serializer = new JavaScriptSerializer(); jsonObj = serializer.Deserialize <dynamic>(ret); JObject jObject = JObject.Parse(ret); // jObject. JArray data = (JArray)jObject["data"]; // JToken pickup_location = data.SelectToken("$..locations[?(@.name=='" + pickup_lookup[this_book.res_pickup].ToString() + "')]"); var vals = data.SelectTokens("$..locations[?(@.name=='" + this_book.res_pickup.Replace("'", "\\'") + "')]"); JToken pickup_location = data.SelectToken("$..locations[?(@.name=='" + this_book.res_pickup.Replace("'", "\\'") + "')]"); try { pickup_d.location_id = (string)(pickup_location["id"]); JToken pickup_detail = pickup_location.Parent.Parent.Parent.SelectToken("pickupDetails[0]"); if ((string)(pickup_detail["id"]) != null) { pickup_d.pickup_detail_id = (string)(pickup_detail["id"]); } }catch (Exception ex) { pickup_d.pickup_detail_id = ""; pickup_d.location_id = ""; } // var het=pickup_detail.Value<string>("pickupDetails"); // var v = pickup_detail.Value<string>("pickupDetails"); // foreach (var item in items) { // dynamic item_date = item["date"]; //get timesAvalable // JArray timesAvail = (JArray)(item["timesAvailable"]); // new product().add_pickup_items(productNum, timesAvail); // datetime } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } return(pickup_d); }
static async Task <pickup> get_supplier_details(int prod_num) { dynamic jsonObj = ""; string ret = ""; pickup pickup_d = new pickup(); string _url = "https://app.resmarksystems.com/public/api/product/" + prod_num + "/pickup"; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = await _client.GetAsync(_url); try { // response.EnsureSuccessStatusCode(); ret = await response.Content.ReadAsStringAsync(); JavaScriptSerializer serializer = new JavaScriptSerializer(); jsonObj = serializer.Deserialize <dynamic>(ret); JObject jObject = JObject.Parse(ret); JArray data = (JArray)jObject["data"]; // var vals = data.SelectTokens("$..locations[?(@.name=='" + this_book.res_pickup.Replace("'", "\\'") + "')]"); // JToken pickup_location = data.SelectToken("$..locations[?(@.name=='" + this_book.res_pickup.Replace("'", "\\'") + "')]"); try { // JArray items = (JArray)data["items"]; foreach (var item in data) { product mproduct = new product(); string zone_id = (string)item["id"]; string zone_name = (string)item["name"]; JArray pickup_data = (JArray)item["pickupDetails"]; Console.Write(" -> getting PickupDetails"); foreach (var pickup in pickup_data) { mproduct.add_supplier_details(prod_num, (string)pickup["name"], zone_id, zone_name); } } // pickup_d.location_id = (string)(pickup_location["id"]); // JToken pickup_detail = pickup_location.Parent.Parent.Parent.SelectToken("pickupDetails[0]"); // if ((string)(pickup_detail["id"]) != null) // pickup_d.pickup_detail_id = (string)(pickup_detail["id"]); } catch (Exception ex) { pickup_d.pickup_detail_id = ""; pickup_d.location_id = ""; Console.WriteLine("Pick up Exception: " + ex.Message); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex.Message); } return(pickup_d); }
static async Task <return_object> add_item_to_cart(string activity_id, string cart_id, booking this_booking, pickup pickup_d) { string ret = ""; return_object returnObject = new return_object(); //string flight_num = get_flight(this_booking.res_comments); dynamic jsonObj = ""; List <string> price_tiers = new List <string>(); try { price_tiers = new product().get_tiers(activity_id); } catch (Exception e) { } string json_body = ""; try { if (price_tiers.Count > 1) { //probably aduly/child json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_a + @""",""" + price_tiers[1] + @""":""" + this_booking.res_y + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}"; } else { if (price_tiers[0] == "Adult") //use Adult { json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_a + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}"; } else { //single tier,, use Unit json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_u + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}"; } } string _url = "https://app.resmarksystems.com/public/api/cart/" + cart_id + "/item"; HttpClient _client = new HttpClient(); _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = await _client.PostAsync(_url, new StringContent(json_body, Encoding.UTF8, "application/json")); // response.EnsureSuccessStatusCode(); ret = await response.Content.ReadAsStringAsync(); JavaScriptSerializer serializer = new JavaScriptSerializer(); jsonObj = serializer.Deserialize <dynamic>(ret); JObject jObject = JObject.Parse(ret); // jObject. returnObject.return_message = (string)jObject["errorMessage"]; returnObject.return_obj = (JObject)jObject["data"]; } catch (Exception ex) { // Console.WriteLine("Add to Cart Exception: " + ex.Message); } return(returnObject); }