public CreateReservationMobileResponse createReservationMobile(CreateReservationMobileRequest reservationMobileRequest, string token)
        {
            CreateReservationMobileResponse result = null;

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(ConstantData.ApiURL.ToString() + "ReservationMobile/CreateReservationMobile");
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    var myContent   = JsonConvert.SerializeObject(reservationMobileRequest);
                    var buffer      = Encoding.UTF8.GetBytes(myContent);
                    var byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");



                    var response = client.PostAsync(client.BaseAddress, byteContent).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        var responseStream = response.Content.ReadAsStringAsync().Result;
                        result = JsonConvert.DeserializeObject <CreateReservationMobileResponse>(responseStream);
                    }
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
        //public SummaryOfChargesPage()
        //{

        //    //if ((int)App.Current.Properties["CustomerId"] == 0)
        //    //{
        //    //    loginIcon.IconImageSource = ImageSource.FromResource("BespokeMobile.Assets.LogInTool.png", assembly);

        //    //}
        //    //else
        //    //{
        //    //    loginIcon.IconImageSource = ImageSource.FromResource("BespokeMobile.Assets.logOutTool.png", assembly);
        //    //}
        //}

        public SummaryOfChargesPage(ReservationView reservationView, VehicleViewByTypeForMobile selectedVehicle)
        {
            InitializeComponent();
            var assembly = typeof(SummaryOfChargesPage);

            this.reservationView             = reservationView;
            summaryMobileRequest             = new GetCalculateSummaryMobileRequest();
            summaryMobileResponsecs          = null;
            ReservationMobileResponse        = null;
            ReservationMobileRequest         = new CreateReservationMobileRequest();
            summaryMobileRequest.reservation = reservationView;
            token = App.Current.Properties["currentToken"].ToString();
            termsandConditionByTypeRequest          = new GetTermsandConditionByTypeRequest();
            termsandConditionByTypeRequest.clientId = Constants.ClientId;
            termsandConditionByTypeRequest.typeId   = 3;
            termsandConditionByTypeResponse         = null;
            this.selectedVehicle = selectedVehicle;
            startDateLabel.Text  = ((DateTime)reservationView.StartDate).ToString("ddd MM/dd/yyyy");
            endDateLabel.Text    = ((DateTime)reservationView.EndDate).ToString("ddd MM/dd/yyyy");
            startTimeLabel.Text  = ((DateTime)reservationView.StartDate).ToString("hh:mm tt");
            endTimeLabel.Text    = ((DateTime)reservationView.EndDate).ToString("hh:mm tt");
            if (selectedVehicle.VehicleTypeImageUrl != null)
            {
                vehilcleTypeImage.Source = ImageSource.FromUri(new Uri(selectedVehicle.VehicleTypeImageUrl));
            }
            vehicleSampleLabel.Text = selectedVehicle.sample;
            vehilcleTypeLabel.Text  = selectedVehicle.VehicleType;
            priceLabel.Text         = "$ " + selectedVehicle.RateDetail.RateTotal.ToString();
            emailInvoiceRequest     = new EmailInvoiceRequest();
            emailResponse           = null;
        }
        private CreateReservationMobileResponse createReservationMobile(CreateReservationMobileRequest reservationMobileRequest, string token)
        {
            CreateReservationMobileResponse response = null;
            ReservationController           reservationController = new ReservationController();
            RegisterController registerController = new RegisterController();

            try
            {
                bool isBookable = registerController.checkBookable((int)reservationMobileRequest.reversationData.CustomerId, token);
                if (isBookable)
                {
                    response = reservationController.createReservationMobile(reservationMobileRequest, token);
                }
                else
                {
                    ApiMessage message = new ApiMessage();
                    message.ErrorMessage = "Can't bookable";
                    message.ErrorCode    = "120";
                    response             = new CreateReservationMobileResponse();
                    response.message     = message;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(response);
        }
        public CreateReservationMobileResponse createReservationMobile(CreateReservationMobileRequest reservationMobileRequest, string token)
        {
            CreateReservationMobileResponse mobileResponse = null;

            try
            {
                mobileResponse = reservationservice.createReservationMobile(reservationMobileRequest, token);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(mobileResponse);
        }
        private bool checkIsbookable(CreateReservationMobileRequest reservationMobileRequest, string token)
        {
            bool isBookable = false;
            RegisterController registerController = new RegisterController();

            try
            {
                isBookable = registerController.checkBookable((int)reservationMobileRequest.reversationData.CustomerId, token);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(isBookable);
        }
        //public SummaryOfChargesPage()
        //{

        //    //if ((int)App.Current.Properties["CustomerId"] == 0)
        //    //{
        //    //    loginIcon.IconImageSource = ImageSource.FromResource("MaxVonGrafKftMobile.Assets.LogInTool.png", assembly);

        //    //}
        //    //else
        //    //{
        //    //    loginIcon.IconImageSource = ImageSource.FromResource("MaxVonGrafKftMobile.Assets.logOutTool.png", assembly);
        //    //}
        //}

        public SummaryOfChargesPage(ReservationView reservationView, VehicleViewByTypeForMobile selectedVehicle)
        {
            InitializeComponent();
            var assembly = typeof(SummaryOfChargesPage);

            this.reservationView             = reservationView;
            summaryMobileRequest             = new GetCalculateSummaryMobileRequest();
            summaryMobileResponsecs          = null;
            ReservationMobileResponse        = null;
            ReservationMobileRequest         = new CreateReservationMobileRequest();
            summaryMobileRequest.reservation = reservationView;
            token = App.Current.Properties["currentToken"].ToString();
            termsandConditionByTypeRequest          = new GetTermsandConditionByTypeRequest();
            termsandConditionByTypeRequest.clientId = Constants.ClientId;
            termsandConditionByTypeRequest.typeId   = 3;
            termsandConditionByTypeResponse         = null;
            this.selectedVehicle = selectedVehicle;
            startDateLabel.Text  = ((DateTime)reservationView.StartDate).ToString("ddd MM/dd/yyyy");
            endDateLabel.Text    = ((DateTime)reservationView.EndDate).ToString("ddd MM/dd/yyyy");
            startTimeLabel.Text  = ((DateTime)reservationView.StartDate).ToString("hh:mm tt");
            endTimeLabel.Text    = ((DateTime)reservationView.EndDate).ToString("hh:mm tt");
            if (selectedVehicle.VehicleImageUrl != null)
            {
                vehilcleTypeImage.Source = ImageSource.FromUri(new Uri(selectedVehicle.VehicleImageUrl));
            }
            vehicleSampleLabel.Text = selectedVehicle.vehicleName;
            vehilcleTypeLabel.Text  = selectedVehicle.VehicleType;
            priceLabel.Text         = "Days: " + selectedVehicle.RateDetail.TotalDays.ToString();
            emailInvoiceRequest     = new EmailInvoiceRequest();
            emailResponse           = null;
            creditCardRequest       = new GetAllCustomerMobileCreditCardRequest();
            creditCards             = null;
            customerId = (int)App.Current.Properties["CustomerId"];

            billingInformation = new BillingInformation();
            submitPaymentandCreateReservationRequest = new SubmitPaymentandCreateReservationRequest();
            PaymentResponse = null;

            //imgSelect.Source = "iconCircleSelected.png";
        }
        private async void SubmitPaymentDetails(CreateReservationMobileRequest reservationMobileRequest)
        {
            submitPaymentandCreateReservationRequest.reservationMobileRequest = reservationMobileRequest;

            int         selectedCardId = 0;
            CreditCards selectedCard   = null;

            foreach (var item in cardDetails)
            {
                if (item.isCardSelect == "iconCircleSelected.png")
                {
                    selectedCardId = item.cardId;
                }
            }


            if (selectedCardId > 0)
            {
                foreach (CreditCards cc in creditCards.listCard)
                {
                    if (cc.CreditCardId == selectedCardId)
                    {
                        selectedCard = cc;
                    }
                }
            }

            if (selectedCard != null)
            {
                billingInformation.FirstName     = Constants.customerDetails.FirstName;
                billingInformation.LastName      = Constants.customerDetails.LastName;
                billingInformation.Email         = Constants.customerDetails.Email;
                billingInformation.Address       = Constants.customerDetails.Address1;
                billingInformation.City          = Constants.customerDetails.City;
                billingInformation.State         = Constants.customerDetails.StateName;
                billingInformation.ZipCode       = Constants.customerDetails.ZipCode;
                billingInformation.Country       = Constants.customerDetails.CountryName;
                billingInformation.phone         = Constants.customerDetails.hPhone;
                billingInformation.CustomerId    = customerId;
                billingInformation.PaymentType   = "Advance Payment";
                billingInformation.PaymentAmount = Convert.ToDouble(summaryMobileResponsecs.rate.ReservationSummary.EstimatedTotal);

                billingInformation.NameOnCard              = selectedCard.NameOnCard;
                billingInformation.CreditCardNumber        = selectedCard.CreditCardNo;
                billingInformation.CreditCardNumberDisplay = selectedCard.CreditCardNoForDisplay;
                billingInformation.SecurityCode            = selectedCard.CreditCardCVSNo;
                billingInformation.ExpiryMonth             = selectedCard.Month;
                billingInformation.ExpiryYear              = selectedCard.Year;
                billingInformation.CreditCardType          = selectedCard.CreditCardType;
                billingInformation.CreditCardId            = (int)selectedCard.CreditCardId;

                billingInformation.LocationId = (int)ReservationMobileRequest.reversationData.StartLocationId;

                billingInformation.FullName    = Constants.customerDetails.FirstName;
                billingInformation.PaymentInfo = new PaymentReferenceInfo();
                //billingInformation.PaymentInfo.ResevationId = ReservationMobileResponse.ReserveId;
                //billingInformation.PaymentInfo.AgreementId = ReservationMobileResponse.ReserveId;
                billingInformation.PaymentInfo.PaymentType    = "Advance Payment";
                billingInformation.PaymentInfo.PaymentDate    = DateTime.Now;
                billingInformation.PaymentInfo.PaymentDateStr = DateTime.Now.ToString();
                billingInformation.PaymentInfo.PaymentMode    = PaymentMode.Payment;
                billingInformation.PaymentInfo.PaymentBy      = Constants.customerDetails.FirstName;
                ReservationController reservationController = new ReservationController();
                submitPaymentandCreateReservationRequest.billingInformation = billingInformation;

                if (App.Current.Properties.ContainsKey("LastCreditCardId"))
                {
                    App.Current.Properties["LastCreditCardId"] = (int)selectedCard.CreditCardId;
                }
                else
                {
                    App.Current.Properties.Add("LastCreditCardId", (int)selectedCard.CreditCardId);
                }
                bool busy = false;
                if (!busy)
                {
                    try
                    {
                        busy = true;
                        await PopupNavigation.Instance.PushAsync(new LoadingPopup("."));

                        await Task.Run(async() =>
                        {
                            try
                            {
                                PaymentResponse = reservationController.SubmitPaymentAndCreateReservation(submitPaymentandCreateReservationRequest, token);
                            }
                            catch (Exception ex)
                            {
                                await PopupNavigation.Instance.PushAsync(new ErrorWithClosePagePopup(ex.Message));
                            }
                        });
                    }
                    catch (Exception ex)
                    {
                        await PopupNavigation.Instance.PushAsync(new ErrorWithClosePagePopup(ex.Message));
                    }
                    finally
                    {
                        busy = false;
                        if (PopupNavigation.Instance.PopupStack.Count == 1)
                        {
                            await PopupNavigation.Instance.PopAllAsync();
                        }
                        if (PopupNavigation.Instance.PopupStack.Count > 1)
                        {
                            if (PopupNavigation.Instance.PopupStack[PopupNavigation.Instance.PopupStack.Count - 1].GetType() != typeof(ErrorWithClosePagePopup))
                            {
                                await PopupNavigation.Instance.PopAllAsync();
                            }
                        }

                        if (PaymentResponse != null)
                        {
                            if (PaymentResponse.Status)
                            {
                                if (PaymentResponse.Data != null)
                                {
                                    if (PaymentResponse.Data.reservationRespose != null)
                                    {
                                        if (PaymentResponse.Data.reservationRespose.ReserveId > 0)
                                        {
                                            await PopupNavigation.Instance.PushAsync(new SuccessPopUp("Congrats! Your payment was successful! You will receive an email once your insurance card has been issued. Please DO NOT attempt to pick up the vehicle until then.", 1));
                                        }
                                        else if (PaymentResponse.RefundStatus)
                                        {
                                            await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Your payment will refund shortly. "));
                                        }
                                        else
                                        {
                                            await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Please contact us for your refund. "));
                                        }
                                    }
                                    else if (PaymentResponse.RefundStatus)
                                    {
                                        await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Your payment will refund shortly. "));
                                    }
                                    else
                                    {
                                        await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Please contact us for your refund. "));
                                    }
                                }
                                else if (PaymentResponse.RefundStatus)
                                {
                                    await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Your payment will refund shortly. "));
                                }
                                else
                                {
                                    await PopupNavigation.Instance.PushAsync(new Error_popup("Sorry, Your booking failed. Please contact us for your refund. "));
                                }
                            }
                            else
                            {
                                await PopupNavigation.Instance.PushAsync(new Error_popup("SORRY, YOUR PAYMENT PROCESS FAILED, Please try again with another card details."));
                            }
                        }
                        else
                        {
                            await PopupNavigation.Instance.PushAsync(new Error_popup("SORRY, YOUR PAYMENT PROCESS FAILED, Please try again with another card details."));
                        }
                    }
                }
            }
            else
            {
                await PopupNavigation.Instance.PushAsync(new Error_popup("Please select a valid card details"));
            }
        }