Ejemplo n.º 1
0
        public CreateBookingResponse CreateBooking(CreateBookingRequest request)
        {
            string                test     = FLEET_API_ROOT_URL + "bookings" + "?access_token=" + FLEET_ACCESS_TOKEN;
            JsonServiceClient     client   = new JsonServiceClient(FLEET_API_ROOT_URL);
            CreateBookingResponse response = client.Post <CreateBookingResponse>("bookings" + "?access_token=" + FLEET_ACCESS_TOKEN, request);

            return(response);
        }
        private async void createBookingRooms(object sender, EventArgs e)
        {
            string msgCreatBooking;

            UserDialogs.Instance.Loading(title: "Creating Booking...").Show();
            var client = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(20)
            };

            JArray roomData = new JArray();

            foreach (var item in listSelectedRoom)
            {
                roomData.Add(new JObject()
                {
                    new JProperty("room_type", item.room_type),
                    new JProperty("start_date", newDateStart.ToString("yyyy-MM-dd")),
                    new JProperty("end_date", newDateEnd.ToString("yyyy-MM-dd")),
                    new JProperty("id", item.id),
                    new JProperty("guest_total", item.selected_room)
                });
            }

            JObject @params = new JObject()
            {
                new JProperty("params", new JObject()
                {
                    new JProperty("auth", new JObject()
                    {
                        new JProperty("token", currentHost.usr_token),
                        new JProperty("url", currentHost.host_url)
                    }),
                    new JProperty("source", new JObject()
                    {
                        new JProperty("source", "Kamooni Traveller App"),
                        new JProperty("channel", "Kamooni Traveller App")
                    }),
                    new JProperty("customer", new JObject()
                    {
                        new JProperty("name", user.name),
                        new JProperty("email", user.email),
                        new JProperty("mobile", "false".Equals(user.mobile) ? "" : user.mobile),
                        new JProperty("token", user.traveller_token)
                    }),
                    new JProperty("roomdata", roomData)
                })
            };

            var data    = @params.ToString();
            var content = new StringContent(data, Encoding.UTF8, "application/json");

            Debug.WriteLine("REQUEST-CreateBooking: " + data);

            try
            {
                HttpResponseMessage response = await client.PostAsync(ApiUri.BASE_URL + ApiUri.CREATE_BOOKING, content);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    UserDialogs.Instance.Loading().Hide();
                    Debug.WriteLine("RESPONSE-AvailableRooms: " + responseContent);

                    CreateBookingResponse createBookingResponse = JsonConvert.DeserializeObject <CreateBookingResponse>(responseContent, App.DefaultSerializerSettings);
                    CreateBookingResult   createBookingResult   = createBookingResponse.result;
                    if (createBookingResult.success)
                    {
                        msgCreatBooking = "Your reservation is almost confirmed! Please click pay to confirm your booking. A payment link is also email to you.";
                        await DisplayAlert("Booking Created Successfully", msgCreatBooking, "Pay Now");

                        //Init new data
                        //frCheckOut.IsVisible = false;
                        //InitializeComponent();
                        //GetHostDetail();
                        //GetRooms();

                        //Open PayNow
                        Device.OpenUri(new Uri(createBookingResult.peach_payment_link_url));

                        //backtohome
                        var page = new HomePage();
                        await Navigation.PushAsync(page, true);
                    }
                    else
                    {
                        msgCreatBooking = createBookingResult.message;
                        await DisplayAlert("Booking Created Unsuccessfully", msgCreatBooking, "OK");
                    }
                }
            }
            catch (TaskCanceledException ex)
            {
                UserDialogs.Instance.Loading().Hide();
                UserDialogs.Instance.Toast(new ToastConfig("Bad Connection Error. Try Again"));
                Debug.WriteLine(ex.Message);
            }
            catch (Exception exx)
            {
                Debug.WriteLine(exx.Message);
                UserDialogs.Instance.Loading().Hide();
                Notifications.Internal.ServerError();
            }
        }