Exemplo n.º 1
0
        private async Task <bool> GetDataFromMystifly(List <Domain.BookFlightResponse> list, Models.BookFlightModel model)
        {
            try
            {
                var supplierAgencyDetails = supplierAgencyServices.GetSupplierRouteBySupplierCodeAndAgencyCode(model.BookFlightEntity.BookFlight.AgencyCode

                                                                                                               , model.BookFlightEntity.BookFlight.SupplierCode, "book/flights");
                List <SupplierAgencyDetails> _supplierAgencyDetailslist = new List <SupplierAgencyDetails> {
                    supplierAgencyDetails
                };
                model.BookFlightEntity.BookFlight.SupplierAgencyDetails = _supplierAgencyDetailslist;
                Paymentinfo paymentinfo = bookingServices.GetPaymentCardDetails(model.BookFlightEntity.BookFlight.AgencyCode);
                model.BookFlightEntity.BookFlight.PaymentInfo = paymentinfo;


                BookingData _BookingData = new BookingData();
                BusinessEntitties.BookFlightModel bookFlightModel = new BusinessEntitties.BookFlightModel();
                bookFlightModel.AirBagDetails  = model.AirBagDetails;
                bookFlightModel.CostBreakuppax = model.CostBreakuppax;
                bookFlightModel.Fareruleseg    = model.Fareruleseg;
                bookFlightModel.Totalfaregroup = model.Totalfaregroup;
                bookFlightModel.BookFlightEntity.BookFlight = model.BookFlightEntity.BookFlight;
                bookFlightModel.costAirMarkUp = model.costAirMarkUp;

                //Check RefID Exist in Database
                bool Exist = false;
                if (model.BookFlightEntity.BookFlight.BookingId != "")
                {
                    Exist = bookingServices.CheckBookingRefIDExist(long.Parse(model.BookFlightEntity.BookFlight.BookingId));
                }
                if (Exist)
                {
                    //Update DataBase With New Price Details and Change Password
                    await bookingServices.UpdateAllDetailsWithRefID(bookFlightModel);
                }
                else
                {
                    // Add New Record in Database
                    _BookingData = await bookingServices.SavingAirBookingFlight(bookFlightModel, supplierAgencyDetails.AgencyID, supplierAgencyDetails.SupplierId);
                }

                //Send Booking Request To Supplier
                string modelStr = JsonConvert.SerializeObject(model.BookFlightEntity);
                var    result   = await partnerClient.GetBookflight(supplierAgencyDetails.BaseUrl, supplierAgencyDetails.RequestUrl, model.BookFlightEntity);

                string responseStr = JsonConvert.SerializeObject(result.Data);
                string jsonData    = JsonConvert.SerializeObject(result.Data);
                string requestStr  = JsonConvert.SerializeObject(model);
                string agencyCode  = model.BookFlightEntity.BookFlight.AgencyCode;
                await supplierAgencyServices.SaveLog("book-Flight", agencyCode, requestStr, jsonData);

                if (jsonData != "null")
                {
                    Domain.BookFlightResponse partnerResponseEntity = JsonConvert.DeserializeObject <Domain.BookFlightResponse>(responseStr);
                    string bookStatus = partnerResponseEntity.BookFlightResult.Status;
                    if (bookStatus == "PRICECHANGED")
                    {
                        //Send Status to website with new bookingRefID
                        partnerResponseEntity.BookFlightResult.BookingId = _BookingData.BookingRefID.ToString();
                        list.Add(partnerResponseEntity);
                        return(true);
                    }
                    else
                    {
                        //Check PNR is Successfully Generated
                        bool pnrstatus = CheckPNRorUniqIDexistornot(partnerResponseEntity);
                        if (pnrstatus)
                        {
                            //Update PNR,BookingStatus and UniqID
                            //Add Errors To Database
                            bookingServices.UpdatePNRandStatus(partnerResponseEntity, _BookingData, bookFlightModel, supplierAgencyDetails.SupplierCode);
                            partnerResponseEntity.BookFlightResult.BookingId = _BookingData.BookingRefID.ToString();
                            list.Add(partnerResponseEntity);
                        }
                        else
                        {
                            list.Add(partnerResponseEntity);
                        }
                    }
                }
                else
                {
                    //Send Error Message to website
                    // Error message = Supplier Note Responding
                    Domain.BookFlightResponse bookFlightResponse = GetErrorTag("0000", "Supplier not responding");
                    list.Add(bookFlightResponse);
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }