コード例 #1
0
        public List <booking> get_bookings(bool ignore_fail)
        {
            List <booking> booking_list = new List <booking>();

            SqlConnection sqlcon = new SqlConnection("Data Source=10.206.100.104\\devapps;Initial Catalog=resmark_import;user=resmark;password=7mmT@XAy;Connection Timeout=5");

            try
            {
                sqlcon.Open();
                string sql = "select top 50 * from view_to_import where res_pickup is NOT NULL and status_migrate='false' and res_date> '" + DateTime.Today + "' and (res_guest IS NOT NULL) order by res_date asc";
                if (ignore_fail)
                {
                    sql = "select top 50 * from view_to_import where res_pickup is NOT NULL and status_migrate='false' and status_response !='' and res_date> '" + DateTime.Today + "' and (res_guest IS NOT NULL) order by res_date asc";
                }
                SqlCommand dbcom = new SqlCommand(sql, sqlcon);

                SqlDataReader dbread = dbcom.ExecuteReader();
                while (dbread.Read())
                {
                    booking tmp = new booking();
                    tmp.id             = Convert.ToInt32(dbread["id"]);
                    tmp.res_num        = Convert.ToInt32(dbread["res_num"]);
                    tmp.res_date       = Convert.ToDateTime(dbread["res_date"]);
                    tmp.res_guest      = Convert.ToString(dbread["res_guest"] == DBNull.Value?"": dbread["res_guest"]);
                    tmp.res_pickup     = Convert.ToString(dbread["res_pickup"]);
                    tmp.res_product    = Convert.ToString(dbread["res_item"]);
                    tmp.res_a          = Convert.ToInt32(dbread["res_A"]);
                    tmp.res_y          = Convert.ToInt32(dbread["res_Y"]);
                    tmp.res_u          = Convert.ToInt32(dbread["res_U"]);
                    tmp.res_comments   = Convert.ToString(dbread["res_Comments"]);
                    tmp.product_number = new product().get_product_num(tmp.res_product.Replace("'", "''"));
                    booking_list.Add(tmp);
                }
                dbread.Close();
            }
            finally
            {
                sqlcon.Dispose();
            }


            return(booking_list);
        }
コード例 #2
0
        static async Task <return_object> add_customer_info(string cart_id, booking this_booking)
        {
            string        ret          = "";
            return_object returnObject = new return_object();

            string flight_num = get_flight(this_booking.res_comments);//extract flight number
            // flight_num = "AA875";
            dynamic    jsonObj   = "";
            string     json_body = @"{""email"":""*****@*****.**"",""firstName"":""" + this_booking.firstname + @""",""lastName"":""" + this_booking.lastname + @""",""title"":""title"",""phone"":""8777688370"",""organization"":""book it"",""postalCode"":""00000"",""state"":""FL"",""country"":""USA"",""Arrival Flight Number"":""" + flight_num + @""",""Departure Airline and Flight Number"":""0000""}";
            string     _url      = "https://app.resmarksystems.com/public/api/cart/" + cart_id + "/customer";
            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.PutAsync(_url, new StringContent(json_body, Encoding.UTF8, "application/json"));

            try
            {
                // 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"];

                //ret = (string)data["id"];
                // var t = cart_id["id"];
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            return(returnObject);
        }
コード例 #3
0
        static async Task <return_object> create_order(string cart_id, booking this_booking)
        {
            string        ret          = "";
            return_object returnObject = new return_object();

            dynamic    jsonObj   = "";
            string     json_body = @"{""id"":""" + cart_id + @""",""billing"":{},""orderId"":null,""referenceId"":""test comment""}";
            string     _url      = "https://app.resmarksystems.com/public/api/order";
            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"));

            try
            {
                // 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"];

                //ret = (string)data["id"];
                // var t = cart_id["id"];
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create Order Exception: " + ex.Message);
            }

            return(returnObject);
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }