Esempio n. 1
0
        public IntegrtaionResult MapBringIntegrationResponse(BringResponseModel bringResponse)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (bringResponse.errors == null)
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.BRING;
                integrtaionResult.TrackingNumber       = bringResponse.consignments[0].confirmation.consignmentNumber;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();
                foreach (var data in bringResponse.consignments[0].confirmation.packages)
                {
                    CourierPieceDetail obj = new CourierPieceDetail();
                    obj.DirectShipmentDetailId = 0;
                    obj.PieceTrackingNumber    = data.packageNumber;
                    obj.ImageUrl = bringResponse.consignments[0].confirmation.links.labels;
                    integrtaionResult.PieceTrackingDetails.Add(obj);
                }
            }
            else
            {
                integrtaionResult.Error         = new FratyteError();
                integrtaionResult.Error.Service = new List <string>();
                foreach (var item in bringResponse.errors)
                {
                    string error = string.Empty;
                    error = item.code + "-" + "" + item.messages;
                    integrtaionResult.Error.Service.Add(error);
                }
                integrtaionResult.Status = false;
            }
            return(integrtaionResult);
        }
Esempio n. 2
0
        public IntegrtaionResult MapEAMGlobalIntegrationResponse(EAMGlobalResponse eamPostalResponse, List <PackageDraft> Packages)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (eamPostalResponse.Status)
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.EAM;
                integrtaionResult.TrackingNumber       = eamPostalResponse.AWB;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();
                int counter = 0;
                for (int i = 0; i < Packages.Count(); i++)
                {
                    for (int j = 0; j < Packages[i].CartoonValue; j++)
                    {
                        CourierPieceDetail obj = new CourierPieceDetail();
                        obj.DirectShipmentDetailId = 0;
                        obj.PieceTrackingNumber    = string.Concat(eamPostalResponse.AWB, counter);
                        obj.ImageUrl = eamPostalResponse.LabelUrl;
                        integrtaionResult.PieceTrackingDetails.Add(obj);
                        counter++;
                    }
                }
            }
            else
            {
                integrtaionResult.Error         = new FratyteError();
                integrtaionResult.Error.Service = new List <string>();
                integrtaionResult.Error.Service.AddRange(eamPostalResponse.ERROR);
                integrtaionResult.Status = false;
            }
            return(integrtaionResult);
        }
        public IntegrtaionResult MapDPDCHIntegrationResponse(DPDChResponseModel dpdchShipmentResponse)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (dpdchShipmentResponse.Error == null)
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.DPDCH;
                integrtaionResult.TrackingNumber       = dpdchShipmentResponse.ShipmentResponses.ParcelLabelNumber[0].ToString();
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();
                foreach (var data in dpdchShipmentResponse.ShipmentResponses.ParcelLabelNumber)
                {
                    CourierPieceDetail obj = new CourierPieceDetail();
                    obj.DirectShipmentDetailId = 0;
                    obj.PieceTrackingNumber    = data;
                    obj.ImageByte = dpdchShipmentResponse.ParcelLabelPDF;
                    integrtaionResult.PieceTrackingDetails.Add(obj);
                }
            }
            else
            {
                integrtaionResult.Error     = dpdchShipmentResponse.Error;
                integrtaionResult.ErrorCode = new List <FrayteApiError>();
                {
                    List <FrayteApiError> _api = new FrayteApiErrorCodeRepository().SaveFinilizeApiError(integrtaionResult.Error, FrayteLogisticServiceType.DPDCH, null);
                    integrtaionResult.ErrorCode = _api;
                }
                integrtaionResult.Status = false;
            }

            return(integrtaionResult);
        }
Esempio n. 4
0
        public IntegrtaionResult MapUSPSIntegrationResponse(USPSResponse response)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (response.trackingNumber != null)
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.USPS;
                integrtaionResult.TrackingNumber       = response.trackingNumber;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();

                CourierPieceDetail obj = new CourierPieceDetail();
                obj.DirectShipmentDetailId = 0;
                obj.PieceTrackingNumber    = response.trackingNumber;
                obj.ImageUrl = response.labelImage;
                integrtaionResult.PieceTrackingDetails.Add(obj);
                return(integrtaionResult);
            }
            else
            {
                integrtaionResult.Status              = false;
                integrtaionResult.Error               = new FratyteError();
                integrtaionResult.Error.IsMailSend    = true;
                integrtaionResult.Error.Custom        = new List <string>();
                integrtaionResult.Error.Address       = new List <string>();
                integrtaionResult.Error.Package       = new List <string>();
                integrtaionResult.Error.Service       = new List <string>();
                integrtaionResult.Error.ServiceError  = new List <string>();
                integrtaionResult.Error.Miscellaneous = new List <string>();
                integrtaionResult.Error.Miscellaneous.Add(response.error);
                return(integrtaionResult);
            }
        }
Esempio n. 5
0
        public void MappingExpressCourierPieceDetail(IntegrtaionResult integrtaionResult, int ExpressShipmentid)
        {
            if (ExpressShipmentid > 0)
            {
                List <int> _shiId = new List <int>();
                for (int i = 0; i < integrtaionResult.PieceTrackingDetails.Count; i++)
                {
                    _shiId = new DirectShipmentRepository().GetExpressDirectShipmentDetailID(ExpressShipmentid);

                    integrtaionResult.PieceTrackingDetails[i].DirectShipmentDetailId = _shiId[i];
                }
            }
        }
Esempio n. 6
0
        public void MappingCourierPieceDetail(IntegrtaionResult integrtaionResult, DirectBookingShipmentDraftDetail directBookingDetail, int DirectShipmentid)
        {
            if (DirectShipmentid > 0)
            {
                int        k = 0, i = 0;
                List <int> _shiId = new List <int>();

                _shiId = new DirectShipmentRepository().GetDirectShipmentDetailID(DirectShipmentid);
                for (i = 0; i < integrtaionResult.PieceTrackingDetails.Count(); i++)
                {
                    integrtaionResult.PieceTrackingDetails[i].DirectShipmentDetailId = _shiId[0];
                }
            }
        }
 public void MappingCourierPieceDetail(IntegrtaionResult integrtaionResult, DirectBookingShipmentDraftDetail directBookingDetail, int DirectShipmentid)
 {
     if (DirectShipmentid > 0)
     {
         int        k = 0, i = 0;
         List <int> _shiId = new List <int>();
         foreach (var Obj in directBookingDetail.Packages)
         {
             _shiId = new DirectShipmentRepository().GetDirectShipmentDetailID(DirectShipmentid);
             for (int j = 1; j <= Obj.CartoonValue; j++)
             {
                 integrtaionResult.PieceTrackingDetails[k].DirectShipmentDetailId = _shiId[i];
                 k++;
             }
             i++;
         }
     }
 }
Esempio n. 8
0
 public void MappingExpressCourierPieceDetail(IntegrtaionResult integrtaionResult, ExpressShipmentModel expessBookingDetail, int ExpressShipmentid)
 {
     if (ExpressShipmentid > 0)
     {
         int        k = 0, i = 0;
         List <int> _shiId = new List <int>();
         foreach (var Obj in expessBookingDetail.Packages)
         {
             _shiId = new DirectShipmentRepository().GetExpressDirectShipmentDetailID(ExpressShipmentid);
             for (int j = 1; j <= Obj.CartonValue; j++)
             {
                 integrtaionResult.PieceTrackingDetails[k].DirectShipmentDetailId = _shiId[i];
                 k++;
             }
             i++;
         }
     }
 }
Esempio n. 9
0
        public IntegrtaionResult MapSkyPostalIntegrationResponse(SkyPostalResponse response)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (response.data[0].label_tracking_number_01 != null)
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.SKYPOSTAL;
                integrtaionResult.TrackingNumber       = response.data[0].label_tracking_number_01;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();

                CourierPieceDetail obj = new CourierPieceDetail();
                obj.DirectShipmentDetailId = 0;
                obj.PieceTrackingNumber    = response.data[0].label_tracking_number_01;
                obj.ImageUrl = response.data[0].label_url_pdf;
                integrtaionResult.PieceTrackingDetails.Add(obj);
                return(integrtaionResult);
            }
            else
            {
                integrtaionResult.Status              = false;
                integrtaionResult.Error               = new FratyteError();
                integrtaionResult.Error.IsMailSend    = true;
                integrtaionResult.Error.Custom        = new List <string>();
                integrtaionResult.Error.Address       = new List <string>();
                integrtaionResult.Error.Package       = new List <string>();
                integrtaionResult.Error.Service       = new List <string>();
                integrtaionResult.Error.ServiceError  = new List <string>();
                integrtaionResult.Error.Miscellaneous = new List <string>();

                for (int i = 0; i < response.data.Count; i++)
                {
                    for (int j = 0; j < response.data[i].error.Count; j++)
                    {
                        integrtaionResult.Error.Miscellaneous.Add(response.data[i].error[j].error_description);
                    }
                }
            }
            return(integrtaionResult);
        }
Esempio n. 10
0
        public IntegrtaionResult MapAUIntegrationResponse(AUResponseModel auResponse)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (auResponse != null)
            {
                integrtaionResult.Status               = auResponse.Status;
                integrtaionResult.CourierName          = FrayteCourierCompany.AU;
                integrtaionResult.TrackingNumber       = auResponse.InvoiceNumber;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();

                for (int i = 0; i < auResponse.Quantity; i++)
                {
                    string             PieceTrackingNumber = string.Concat(auResponse.InvoiceNumber, i.ToString());
                    CourierPieceDetail obj = new CourierPieceDetail();
                    obj.DirectShipmentDetailId = 0;
                    obj.PieceTrackingNumber    = PieceTrackingNumber;
                    obj.ImageUrl  = auResponse.TempDownload_Folder;
                    obj.LabelName = auResponse.TempDownlaodLabelName;
                    integrtaionResult.PieceTrackingDetails.Add(obj);
                }
            }
            else
            {
                integrtaionResult.Error = new FratyteError();
                integrtaionResult.Error.Miscellaneous = new List <string>();
                integrtaionResult.Error.Miscellaneous.Add(auResponse.Error);

                integrtaionResult.ErrorCode = new List <FrayteApiError>();
                {
                    List <FrayteApiError> _api = new FrayteApiErrorCodeRepository().SaveFinilizeApiError(integrtaionResult.Error, FrayteLogisticServiceType.DPD, null);
                    integrtaionResult.ErrorCode = _api;
                }
                integrtaionResult.Status = false;
            }

            return(integrtaionResult);
        }
Esempio n. 11
0
        public IntegrtaionResult MapCanadaPostIntegrationResponse(EtowerResponseModel eTowerResponse, List <OrderItem> orderItems)
        {
            IntegrtaionResult integrtaionResult = new IntegrtaionResult();

            if (eTowerResponse.status == "Success")
            {
                integrtaionResult.Status               = true;
                integrtaionResult.CourierName          = FrayteCourierCompany.CANADAPOST;
                integrtaionResult.TrackingNumber       = eTowerResponse.data[0].trackingNo;
                integrtaionResult.PickupRef            = null;
                integrtaionResult.PieceTrackingDetails = new List <CourierPieceDetail>();
                int counter = 1;
                for (int i = 0; i < orderItems.Count; i++)
                {
                    CourierPieceDetail obj = new CourierPieceDetail();
                    obj.DirectShipmentDetailId = 0;
                    obj.PieceTrackingNumber    = string.Concat(eTowerResponse.data[0].trackingNo, counter);
                    obj.ImageByte = eTowerResponse.data[0].labelContent;
                    integrtaionResult.PieceTrackingDetails.Add(obj);
                    counter++;
                }
            }
            else
            {
                integrtaionResult.Error         = new FratyteError();
                integrtaionResult.Error.Service = new List <string>();
                foreach (var item in eTowerResponse.errors)
                {
                    string error = string.Empty;
                    error = item.code + "-" + "" + item.message;
                    integrtaionResult.Error.Service.Add(error);
                }

                integrtaionResult.Status = false;
            }

            return(integrtaionResult);
        }
Esempio n. 12
0
        public void MappingFrayteResponseToExpressBookingDetail(ExpressShipmentModel ExpressDetail, IntegrtaionResult intResult, ExpressShipmentResponseModel Response)
        {
            Response.ShipmentBookingId = ExpressDetail.ExpressId;
            Response.Status            = true;
            Response.Description       = "";
            Response.AWBNumber         = ExpressDetail.AWBNumber.Substring(0, 3) + " " + ExpressDetail.AWBNumber.Substring(3, 3) + " " + ExpressDetail.AWBNumber.Substring(6, 3) + " " + ExpressDetail.AWBNumber.Substring(9, 3);
            Response.TrackingNumber    = intResult.TrackingNumber.Replace("Order_", "");
            Response.CreatedOn         = DateTime.UtcNow.ToString("dd-MMM-yyyy");
            Response.Currency          = ExpressDetail.DeclaredCurrency.CurrencyCode;
            Response.FromAddress       = new FromAddressDto()
            {
                CompanyName = ExpressDetail.ShipFrom.CompanyName,
                FirstName   = ExpressDetail.ShipFrom.FirstName,
                LastName    = ExpressDetail.ShipFrom.LastName,
                Email       = ExpressDetail.ShipFrom.Email,
                Phone       = ExpressDetail.ShipFrom.Phone,
                Address     = new ShipAddressDto()
                {
                    Address1    = ExpressDetail.ShipFrom.Address,
                    Address2    = ExpressDetail.ShipFrom.Address2,
                    Area        = ExpressDetail.ShipFrom.Area,
                    City        = ExpressDetail.ShipFrom.City,
                    CountryCode = ExpressDetail.ShipFrom.Country.Code,
                    Postcode    = ExpressDetail.ShipFrom.PostCode,
                    State       = ExpressDetail.ShipFrom.State
                }
            };
            Response.ToAddress = new ToAddressDto()
            {
                CompanyName = ExpressDetail.ShipTo.CompanyName,
                FirstName   = ExpressDetail.ShipTo.FirstName,
                LastName    = ExpressDetail.ShipTo.LastName,
                Email       = ExpressDetail.ShipTo.Email,
                Phone       = ExpressDetail.ShipTo.Phone,
                Address     = new ShipAddressDto()
                {
                    Address1    = ExpressDetail.ShipTo.Address,
                    Address2    = ExpressDetail.ShipTo.Address2,
                    Area        = ExpressDetail.ShipTo.Area,
                    City        = ExpressDetail.ShipTo.City,
                    CountryCode = ExpressDetail.ShipTo.Country.Code,
                    Postcode    = ExpressDetail.ShipTo.PostCode,
                    State       = ExpressDetail.ShipTo.State
                }
            };

            Response.CustomInfo = new ApiCustomInformation()
            {
                ContentsType        = ExpressDetail.CustomInformation.ContentsType,
                ContentsExplanation = ExpressDetail.CustomInformation.ContentsExplanation,
                RestrictionType     = ExpressDetail.CustomInformation.RestrictionType,
                RestrictionComments = ExpressDetail.CustomInformation.RestrictionComments,
                CustomsSigner       = ExpressDetail.CustomInformation.CustomsSigner,
                NonDeliveryOption   = ExpressDetail.CustomInformation.NonDeliveryOption,
            };
            var FilesArray = Directory.GetFiles(AppSettings.WebApiPath + "/PackageLabel/Express/" + ExpressDetail.ExpressId);

            if (FilesArray.Length > 0)
            {
                var AllFile = FilesArray.Where(a => a.Contains("All")).FirstOrDefault();
                if (!string.IsNullOrEmpty(AllFile))
                {
                    Response.AllLlabelUrl = AppSettings.LabelVirtualPath + "/PackageLabel/Express/" + FilesArray.Where(a => a.Contains("All")).FirstOrDefault().Split('/').LastOrDefault();
                }
                else
                {
                    Response.AllLlabelUrl = AppSettings.LabelVirtualPath + "/PackageLabel/Express/" + FilesArray.FirstOrDefault().Split('/').LastOrDefault();
                }
            }
            else
            {
                Response.AllLlabelUrl = "";
            }
        }
        public bool SaveTrackingDetail(DirectBookingShipmentDraftDetail directBookingDetail, IntegrtaionResult result, int DirectShipmentid)
        {
            var count = 1;

            foreach (var Obj in result.PieceTrackingDetails)
            {
                Frayte.Services.Models.Package package = new Frayte.Services.Models.Package();
                package.DirectShipmentDetailId = Obj.DirectShipmentDetailId;

                package.LabelName = Obj.PieceTrackingNumber;
                new DirectShipmentRepository().SavePackageDetail(package, "", Obj.DirectShipmentDetailId, directBookingDetail.CustomerRateCard.CourierName, count);
                count++;
            }
            return(true);
        }
Esempio n. 14
0
        public IHttpActionResult ExpressShipmentBooking(ExpressShipmentRequest Shipment)
        {
            try
            {
                List <FrayteUploadshipment> _upload = new ExpressShipmentRepository().JsonValidate(Shipment, FrayteCallingType.FrayteApi);
                if (_upload.Count > 0)
                {
                    return(Ok(_upload[0].Errors));
                }
                else
                {
                    var shipment = new ExpressShipmentRepository().MappingFrayteRequestToExpressBookingDetail(Shipment);
                    ExpressShipmentResponseModel ExpressResponse = new ExpressShipmentResponseModel();
                    ExpressShipmentModel         model           = new ExpressRepository().SaveShipment(shipment);
                    if (shipment.Error.Status && model.ShipmentStatusId == (int)FrayteExpressShipmentStatus.Scanned)
                    {
                        #region Logistic Integration
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                        {
                            #region DHL Integration
                            IntegrtaionResult result = new IntegrtaionResult();
                            //step 1. Mapping With express model to ShipmentRequestDto

                            var shipmentRequestDto = new DHLRepository().MapExpressShipmentToDHLShipmentRequestDto(shipment);

                            //Step 2. Create Xml
                            string shipmentXML = string.Empty;
                            //Version5.0

                            shipmentXML = new DHLRepository().CreateXMLForDHL(shipmentRequestDto);


                            //Version 6.2  not in use
                            // shipmentXML = new DHLUKRepositry().CreateXMLForDHLUK(shipmentRequestDto);
                            string xml_in = string.Empty;

                            xml_in = File.ReadAllText(@shipmentXML);

                            //step 3. Create Shipment
                            var DHLResponse = new DHLResponseDto();

                            DHLResponse = new DHLRepository().CreateShipment(xml_in, shipmentRequestDto);

                            //step 4. Mapping ShipmentResonse to IntegrtaionResult

                            result = new DHLRepository().MapDHLIntegrationResponse(DHLResponse);

                            if (result.Status)
                            {
                                if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                                {
                                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                                    try
                                    {
                                        new ExpressRepository().MappingCourierPieceDetail(result, shipment);
                                    }
                                    catch (Exception Ex)
                                    {
                                        throw (new FrayteApiException("MapDHLCourierPieceDetailError", Ex));
                                    }
                                }
                                //Step3 : Save Main Tracking Number
                                new ExpressRepository().SaveMainTrackingDetail(shipment, result, xml_in, "");
                                new ExpressRepository().SaveTrackingDetail(shipment, result);


                                // AfterShipIntegration

                                if (AppSettings.ApplicationMode == FrayteApplicationMode.Live)
                                {
                                    FrayteAfterShipTracking aftershipTracking = new AftershipTrackingRepository().MapDirectShipmentObjToAfterShip(shipment.ExpressId, FrayteShipmentServiceType.Express);

                                    if (aftershipTracking != null && AppSettings.ApplicationMode == FrayteApplicationMode.Live)
                                    {
                                        //Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Integration in aftership"));
                                        new AftershipTrackingRepository().CreateTracking(aftershipTracking);
                                    }
                                }


                                //Step4:  //Start downloading the images from DHL server and making PDF
                                var count      = 1;
                                var totalpiece = result.PieceTrackingDetails.Count();
                                totalpiece = totalpiece - 1;

                                foreach (var data in result.PieceTrackingDetails.Take(totalpiece))
                                {
                                    if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                                    {
                                        // Step3.1
                                        data.LabelName = new DHLRepository().ExpressDownloadDHLImage(data, totalpiece, count, shipment.ExpressId);
                                    }
                                    if (!data.PieceTrackingNumber.Contains("AirwayBillNumber_"))
                                    {
                                        //Step3.2
                                        new ExpressRepository().SavePackageDetail(data, result.CourierName);
                                    }
                                    count++;
                                }
                                var CourierPieceDetail = result.PieceTrackingDetails.Where(t => t.PieceTrackingNumber.Contains("AirwayBillNumber_")).FirstOrDefault();
                                if (CourierPieceDetail != null)
                                {
                                    var data1 = new DHLRepository().ExpressDownloadDHLImage(CourierPieceDetail, totalpiece, 0, shipment.ExpressId);

                                    // save all dhl image
                                    new ExpressRepository().SaveLogisticLabelImage(shipment.ExpressId, data1);
                                }
                                if (result.Status)
                                {
                                    var status = Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    // Send Booking confirmation email
                                    if (status.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                }
                            }
                            else
                            {
                                shipment.Error = result.Error;
                            }
                            #endregion
                        }
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.Yodel)
                        {
                            #region Yodel Integration

                            //Map Direct Booking object with parcel hub objects
                            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapExpressBookingDetailToShipmentRequest(shipment);
                            //Create shipment in Parcel hub
                            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateShipment(request);
                            if (response.Error.IsMailSend)
                            {
                                //Send error mail to developer
                                shipment.Error               = new FratyteError();
                                shipment.Error.Custom        = new List <string>();
                                shipment.Error.Package       = new List <string>();
                                shipment.Error.Address       = new List <string>();
                                shipment.Error.Service       = new List <string>();
                                shipment.Error.ServiceError  = new List <string>();
                                shipment.Error.Miscellaneous = new List <string>();
                                shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                shipment.Error               = response.Error;

                                new DirectShipmentRepository().SaveExpressEasyPosyPickUpObject(Newtonsoft.Json.JsonConvert.SerializeObject(response.Error).ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(shipment).ToString(), shipment.ExpressId);
                            }
                            else
                            {
                                //Mapping ShipmentResonse to IntegrtaionResult
                                var result = new ParcelHubRepository().MappingExpressParcelHubToIntegrationResult(shipment, response, null);

                                if (result.Status)
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ParcelHubRepository().MappingExpressCourierPieceDetail(result, shipment, shipment.ExpressId);

                                    //Save Package Label Tracking detail
                                    new ExpressRepository().SaveMainTrackingDetail(shipment, result, response.Request, response.Response);

                                    FratyteError Error = new ParcelHubRepository().DownloadExpressParcelHubPackageImage(shipment, result, shipment.ExpressId);

                                    //Start Making Final One pdf file for all package label
                                    Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    if (result.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                    shipment.Error = new FratyteError()
                                    {
                                        Status = result.Status,
                                    };
                                }
                                else
                                {
                                    if (result.Error.IsMailSend)
                                    {
                                        //Send error mail to developer
                                        shipment.Error               = new FratyteError();
                                        shipment.Error.Custom        = new List <string>();
                                        shipment.Error.Package       = new List <string>();
                                        shipment.Error.Address       = new List <string>();
                                        shipment.Error.Service       = new List <string>();
                                        shipment.Error.ServiceError  = new List <string>();
                                        shipment.Error.Miscellaneous = new List <string>();
                                        shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                        shipment.Error               = result.Error;
                                    }
                                }
                            }
                            #endregion
                        }
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.Hermes)
                        {
                            #region Hermes Integration

                            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapExpressBookingDetailToShipmentRequest(shipment);
                            //Create shipment in Parcel hub
                            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateHermesShipment(request);

                            if (response.Error.IsMailSend)
                            {
                                //Send error mail to developer
                                shipment.Error               = new FratyteError();
                                shipment.Error.Custom        = new List <string>();
                                shipment.Error.Package       = new List <string>();
                                shipment.Error.Address       = new List <string>();
                                shipment.Error.Service       = new List <string>();
                                shipment.Error.ServiceError  = new List <string>();
                                shipment.Error.Miscellaneous = new List <string>();
                                shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                shipment.Error               = response.Error;

                                new DirectShipmentRepository().SaveExpressEasyPosyPickUpObject(Newtonsoft.Json.JsonConvert.SerializeObject(response.Error).ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(shipment).ToString(), shipment.ExpressId);
                            }
                            else
                            {
                                //Mapping ShipmentResonse to IntegrtaionResult
                                var result = new ParcelHubRepository().MappingExpressParcelHubToIntegrationResult(shipment, response, null);

                                if (result.Status)
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ParcelHubRepository().MappingExpressCourierPieceDetail(result, shipment, shipment.ExpressId);

                                    //Save Package Label Tracking detail
                                    new ExpressRepository().SaveMainTrackingDetail(shipment, result, response.Request, response.Response);

                                    //Start Making Final One pdf file for all package label
                                    Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);

                                    if (result.Status)
                                    {
                                        ExpressEmailModel emailModel = new ExpressEmailModel();
                                        emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                        if (emailModel != null)
                                        {
                                            new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                        }
                                        new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                    }
                                    shipment.Error = new FratyteError()
                                    {
                                        Status = result.Status,
                                    };
                                }
                                else
                                {
                                    if (result.Error.IsMailSend)
                                    {
                                        //Send error mail to developer
                                        shipment.Error               = new FratyteError();
                                        shipment.Error.Custom        = new List <string>();
                                        shipment.Error.Package       = new List <string>();
                                        shipment.Error.Address       = new List <string>();
                                        shipment.Error.Service       = new List <string>();
                                        shipment.Error.ServiceError  = new List <string>();
                                        shipment.Error.Miscellaneous = new List <string>();
                                        shipment.Error.MiscErrors    = new List <FrayteKeyValue>();
                                        shipment.Error               = result.Error;
                                    }
                                }
                            }

                            #endregion
                        }
                        if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                        {
                            #region EAM Global Integration

                            IntegrtaionResult result = new IntegrtaionResult();
                            if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                            {
                                var    shipmentRequestDto = new EAMGlobalRepository().MapExpressBookingDetailToShipmentRequestDto(shipment);
                                string shipmentXML        = new EAMGlobalRepository().CreateXMLForEAM(shipmentRequestDto);
                                string xml_in             = File.ReadAllText(@shipmentXML);

                                //Create Shipment
                                var shipmentResult = new EAMGlobalRepository().CreateShipment(xml_in, shipment.ExpressId);
                                result = new EAMGlobalRepository().MapExpressEAMGlobalIntegrationResponse(shipmentResult, shipment.Packages);
                            }

                            if (result.Status)
                            {
                                if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                                {
                                    //Mapping ShipmentResult to IntegrtaionResult
                                    new ExpressRepository().MappingCourierPieceDetail(result, shipment);
                                }

                                //Save Package Label Tracking detail
                                new ExpressRepository().SaveMainTrackingDetail(shipment, result, "", "");

                                //Start downloading the images from DPD server and making PDF
                                var count = 1;
                                foreach (var data in result.PieceTrackingDetails)
                                {
                                    if (shipment.Service.HubCarrier.ToUpper().Contains(FrayteCourierCompany.EAM))
                                    {
                                        //Step3.1
                                        data.LabelName = new EAMGlobalRepository().DownloadExpressEAMImageTOPDF(data, result.PieceTrackingDetails.Count(), count, shipment.ExpressId, shipment.Service);
                                    }
                                    // Step3.2
                                    new ExpressRepository().SavePackageDetail(data, result.CourierName);
                                    count++;
                                }
                                //Step:4 Generate PDF
                                Generate_Seperate_PackageLabelPDF(shipment.ExpressId, shipment, result);
                                if (result.Status)
                                {
                                    ExpressEmailModel emailModel = new ExpressEmailModel();
                                    emailModel = new ExpressRepository().Fill_EXS_E1Model(emailModel, shipment);
                                    if (emailModel != null)
                                    {
                                        new ExpressRepository().SendEmail_EXS_E1(emailModel);
                                    }
                                    new ExpressShipmentRepository().MappingFrayteResponseToExpressBookingDetail(shipment, result, ExpressResponse);
                                }

                                shipment.Error = new FratyteError()
                                {
                                    Status = result.Status,
                                };
                            }
                            else
                            {
                                shipment.Error = result.Error;
                            }

                            #endregion
                        }

                        #endregion

                        return(Ok(ExpressResponse));
                    }
                }
            }
            catch (Exception Ex)
            {
                string error = ReadException(Ex);
                ExpressErrorResponse Response = new FrayteApiErrorCodeRepository().SaveExpressApiError(error);
                return(Ok(Response));
            }
            return(Ok());
        }
Esempio n. 15
0
        public FrayteResult Generate_Seperate_PackageLabelPDF(int DirectShipmentId, ExpressShipmentModel shipment, IntegrtaionResult integrtaionResult)
        {
            FrayteResult result = new FrayteResult();

            result.Errors = new List <string>();

            List <string> list  = new List <string>();
            List <string> list1 = new List <string>();


            var Packages = new ExpressRepository().GetPackageDetails(DirectShipmentId);

            if (Packages != null)
            {
                if (shipment.Service.HubCarrier != FrayteCourierCompany.AU && shipment.Service.HubCarrier.ToUpper() != FrayteCourierCompany.SKYPOSTAL && shipment.Service.HubCarrier != FrayteCourierCompany.BRING && shipment.Service.HubCarrier != FrayteCourierCompany.DPDCH && shipment.Service.HubCarrier != FrayteCourierCompany.EAM && shipment.Service.HubCarrier.ToUpper() != FrayteCourierCompany.CANADAPOST && shipment.Service.HubCarrier != FrayteCourierCompany.Hermes)
                {
                    foreach (var pack in Packages)
                    {
                        var packageTracking = getPackageImamagePath(pack.ExpressDetailId);
                        if (packageTracking != null && packageTracking.Count > 0)
                        {
                            foreach (var data in packageTracking)
                            {
                                list.Add(data.PackageLabelName);
                                list1.Add(data.PackageLabelName);
                                var resultReport = new Report.Generator.ManifestReport.PackageLabelReport().ExpressGenerateAllLabelReport(DirectShipmentId, null, list1, shipment.Service.HubCarrier, "");
                                if (!resultReport.Status)
                                {
                                    result.Status = false;
                                    result.Errors.Add("All the labels Pdf are not generated for " + DirectShipmentId.ToString());
                                }
                                list1.Remove(data.PackageLabelName);
                            }
                        }
                        else
                        {
                            result.Status = false;
                            result.Errors.Add("All the labels Pdf are not generated for " + DirectShipmentId.ToString());
                        }
                    }
                }


                string RateType       = shipment.Service.RateType;
                string CourierCompany = shipment.Service.HubCarrier;
                string TrackingNo     = new ExpressRepository().GetTrackingNo(DirectShipmentId);
                string labelName      = string.Empty;
                if (shipment.Service.HubCarrier == FrayteCourierCompany.Yodel)
                {
                    labelName = FrayteShortName.Yodel;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.Hermes)
                {
                    labelName = FrayteShortName.Hermes;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.UKMail)
                {
                    labelName = FrayteShortName.UKMail;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                {
                    labelName = FrayteShortName.DHL;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.TNT)
                {
                    labelName = FrayteShortName.TNT;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.UPS)
                {
                    labelName = FrayteShortName.UPS;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.DPD)
                {
                    labelName = FrayteShortName.DPD;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.AU)
                {
                    labelName = FrayteShortName.AU;
                }
                else if (shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.SKYPOSTAL)
                {
                    labelName = FrayteShortName.SKYPOSTAL;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.BRING)
                {
                    labelName = FrayteShortName.BRING;
                }
                else if (shipment.Service.HubCarrier == FrayteCourierCompany.EAM)
                {
                    labelName = FrayteShortName.EAM;
                }
                else if (shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.CANADAPOST)
                {
                    labelName = FrayteShortName.CANADAPOST;
                }
                string LogisticLabel = string.Empty;

                int totalCartoonValue = shipment.Packages.Sum(k => k.CartonValue);
                if (!string.IsNullOrEmpty(shipment.Service.RateType))
                {
                    if (TrackingNo.Contains("Order_"))
                    {
                        var Trackinginfo = TrackingNo.Replace("Order_", "");
                        LogisticLabel = labelName + "_" + Trackinginfo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (All)" + ".pdf";
                    }
                    else
                    {
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.DPD || shipment.Service.HubCarrier == FrayteCourierCompany.TNT)
                        {
                            if (shipment.Service.HubCarrier == FrayteCourierCompany.DPD)
                            {
                                for (int i = 0; i < integrtaionResult.PieceTrackingDetails.Count; i++)
                                {
                                    int    numberofpiece = i + 1;
                                    string Image         = labelName + "_" + integrtaionResult.PieceTrackingDetails[i].PieceTrackingNumber + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (" + numberofpiece + " of " + totalCartoonValue + ")" + ".html";
                                    LogisticLabel += Image + ";";
                                }
                            }
                            else
                            {
                                for (int i = 1; i <= totalCartoonValue; i++)
                                {
                                    string Image = labelName + "_" + TrackingNo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (" + i + " of " + totalCartoonValue + ")" + ".html";
                                    LogisticLabel += Image + ";";
                                }
                            }
                        }
                        else
                        {
                            if (shipment.Service.HubCarrier == FrayteCourierCompany.AU || shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.SKYPOSTAL || shipment.Service.HubCarrier == FrayteCourierCompany.BRING || shipment.Service.HubCarrier == FrayteCourierCompany.DPDCH || shipment.Service.HubCarrier.Contains(FrayteCourierCompany.EAM) || shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.CANADAPOST)
                            {
                                LogisticLabel = integrtaionResult.PieceTrackingDetails[0].LabelName;
                            }
                            else
                            {
                                LogisticLabel = labelName + "_" + TrackingNo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (All)" + ".pdf";
                            }
                        }
                    }
                }
                else
                {
                    if (TrackingNo.Contains("Order_"))
                    {
                        var Trackinginfo = TrackingNo.Replace("Order_", "");
                        LogisticLabel = labelName + "_" + Trackinginfo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (All)" + ".pdf";
                    }
                    else
                    {
                        if (shipment.Service.HubCarrier == FrayteCourierCompany.DPD || shipment.Service.HubCarrier == FrayteCourierCompany.TNT)
                        {
                            if (shipment.Service.HubCarrier == FrayteCourierCompany.DPD)
                            {
                                for (int i = 1; i <= integrtaionResult.PieceTrackingDetails.Count; i++)
                                {
                                    int    numberofpiece = i + 1;
                                    string Image         = labelName + "_" + integrtaionResult.PieceTrackingDetails[i].PieceTrackingNumber + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (" + numberofpiece + " of " + totalCartoonValue + ")" + ".html";
                                    LogisticLabel += Image + ";";
                                }
                            }
                            else
                            {
                                for (int i = 1; i <= totalCartoonValue; i++)
                                {
                                    string Image = labelName + "_" + TrackingNo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (" + i + " of " + totalCartoonValue + ")" + ".html";
                                    LogisticLabel += Image + ";";
                                }
                            }
                        }
                        else
                        {
                            if (shipment.Service.HubCarrier == FrayteCourierCompany.AU || shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.SKYPOSTAL || shipment.Service.HubCarrier == FrayteCourierCompany.BRING || shipment.Service.HubCarrier == FrayteCourierCompany.DPDCH || shipment.Service.HubCarrier == FrayteCourierCompany.EAM || shipment.Service.HubCarrier.ToUpper() == FrayteCourierCompany.CANADAPOST)
                            {
                                LogisticLabel = integrtaionResult.PieceTrackingDetails[0].LabelName;
                            }
                            else
                            {
                                LogisticLabel = labelName + "_" + TrackingNo + "_" + DateTime.Now.ToString("dd_MM_yyyy") + " (All)" + ".pdf";
                            }
                        }
                    }
                }
                if (shipment.Service.HubCarrier == FrayteCourierCompany.DHL)
                {
                    var shipmentImange = new ExpressRepository().GetShipmentImage(DirectShipmentId);
                    list.Add(shipmentImange.LogisticLabelImage);
                }
                // After Creting label  save in DirectShipmentTable
                if (shipment.Service.HubCarrier != FrayteCourierCompany.DPD && shipment.Service.HubCarrier.ToUpper() != FrayteCourierCompany.TNT && shipment.Service.HubCarrier != FrayteCourierCompany.AU && shipment.Service.HubCarrier.ToUpper() != FrayteCourierCompany.SKYPOSTAL && shipment.Service.HubCarrier != FrayteCourierCompany.BRING && shipment.Service.HubCarrier != FrayteCourierCompany.DPDCH && shipment.Service.HubCarrier != FrayteCourierCompany.EAM && shipment.Service.HubCarrier.ToUpper() != FrayteCourierCompany.CANADAPOST && shipment.Service.HubCarrier != FrayteCourierCompany.Hermes)
                {
                    var Result = new Report.Generator.ManifestReport.PackageLabelReport().ExpressGenerateAllLabelReport(DirectShipmentId, shipment, list, shipment.Service.HubCarrier, LogisticLabel);
                    result.Status = true;
                    if (Result.Status)
                    {
                        new ExpressRepository().SaveLogisticLabel(DirectShipmentId, LogisticLabel);
                        result.Status = true;
                    }
                }
                else
                {
                    new ExpressRepository().SaveLogisticLabel(DirectShipmentId, LogisticLabel);
                    result.Status = true;
                }
            }
            else
            {
                result.Status = false;
                result.Errors.Add("All the labels Pdf are not generated for " + DirectShipmentId.ToString());
            }
            return(result);
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentParcelHubIntegration(FrayteUploadshipment res)
        {
            FrayteResult      FR     = new FrayteResult();
            IntegrtaionResult result = new IntegrtaionResult();
            var count               = 0;
            int DirectShipmentid    = 0;
            var directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);

            // Parcelhub Integration starts
            //Step 2: Shipment Integrations
            #region Parcel Hub Integration

            //Map Direct Booking object with parcel hub objects
            Frayte.Services.Models.ParcelHub.ParcelHubShipmentRequest request = new ParcelHubRepository().MapDirectBookingDetailToShipmentRequest(directBookingDetail);

            //Create shipment in Parcel hub
            Frayte.Services.Models.ParcelHub.ParcelHubResponse response = new ParcelHubRepository().CreateShipment(request);

            if (response.Error.IsMailSend)
            {
                if (directBookingDetail.Error.IsMailSend)
                {
                    //Send error mail to developer
                    new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, response.Error);
                }
            }
            else
            {
                //Mapping ShipmentResonse to IntegrtaionResult
                result = new ParcelHubRepository().MappingParcelHubToIntegrationResult(directBookingDetail, response, null);

                if (result.Status)
                {
                    //Save Shipment Detail Into Our DB
                    DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                    if (DirectShipmentid > 0)
                    {
                        var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    }
                    //Mapping ShipmentResult to IntegrtaionResult
                    new ParcelHubRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);

                    //Save Package Label Tracking detail
                    new ParcelHubRepository().SaveTrackingDetail(directBookingDetail, result, DirectShipmentid);

                    //Start downloading the images from UPS server and making PDF
                    FratyteError Error = new ParcelHubRepository().DownloadParcelHubPackageImage(directBookingDetail, result, DirectShipmentid);
                }
                else
                {
                    if (result.Error.IsMailSend)
                    {
                        new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, res.CustomerId);
                        //Send error mail to developer
                        new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
                    }
                }
            }


            #endregion

            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }
        public Tuple <FrayteResult, DirectBookingShipmentDraftDetail, int> DBUploadShipmentDHLIntegration(FrayteUploadshipment res)
        {
            IntegrtaionResult result = new IntegrtaionResult();
            FrayteResult      FR     = new FrayteResult();
            //string xsUserFolder = @"C:\FMS\" + "FrayteSchedularlog.txt";
            string xsUserFolder = @"D:\ProjectFrayte\" + "FrayteScheduler.txt";

            BaseLog.Instance.SetLogFile(xsUserFolder);
            Logger _log                = Get_Log();
            int    DirectShipmentid    = 0;
            var    directBookingDetail = new DirectBookingUploadShipmentRepository().DirectBookingObj(res);

            #region COLLECTION Date

            DateTime mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value;
            DateTime maxdatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);

            if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Sunday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(1);
            }
            else if (System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(mindatetime.DayOfWeek) == FraytePickUpDay.Saturday)
            {
                mindatetime = directBookingDetail.ReferenceDetail.CollectionDate.Value.AddDays(2);
            }

            directBookingDetail.ReferenceDetail.CollectionDate = mindatetime;
            #endregion
            _log.Error("Get direct Booking Object");
            //update customerratecard in draft
            new DirectShipmentRepository().SaveDirectShipmnetDetail(directBookingDetail);
            _log.Error("saved direct Booking Object");
            //step1. Mapping With directBookingDetail to ShipmentRequestDto
            var shipmentRequestDto = new DHLRepository().MapDirectBookingDetailToDHLShipmentRequestDto(directBookingDetail);

            //Step 2. Create Xml
            var shipmentXML = new DHLRepository().CreateXMLForDHL(shipmentRequestDto);
            _log.Error("done xml dhl shipment");
            _log.Error(shipmentXML);
            string xml_in = "";
            try
            {
                xml_in = File.ReadAllText(shipmentXML);
                //xml_in = File.ReadAllText(@"C:\FMS\app.godemowithus.com\WebApi\UploadFiles\PDFGenerator\HTMLFile\tempDHLShipment.xml");
            }
            catch (Exception e)
            {
                _log.Error(e.Message);
                _log.Error(e.InnerException);
                _log.Error(e.StackTrace);
            }
            _log.Error("reading xml dhl shipment");
            //step 3. Create Shipment
            var DHLResponse = new DHLRepository().CreateShipment(xml_in, shipmentRequestDto);
            // _log.Error("done integration dhl shipment" + DHLResponse.Error.ErrorDescription.ToString());
            //step 4. Mapping ShipmentResonse to IntegrtaionResult
            result = new DHLRepository().MapDHLIntegrationResponse(DHLResponse);
            if (result.Status)
            {
                //step2. After Shipment Create need to save the information in database
                DirectShipmentid = new DirectShipmentRepository().SaveShipment(directBookingDetail, result);
                if (DirectShipmentid > 0)
                {
                    _log.Error("done save dhl shipment in db" + directBookingDetail.CustomerId);
                    var Id = new eCommerceUploadShipmentRepository().SaveBatchProcessProcessedShipment(1, directBookingDetail.CustomerId);
                    _log.Error(Id.ToString());
                }
                _log.Error("done save dhl shipment in db");
                if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                {
                    //Step 1.1 Mapping ShipmentResult to IntegrtaionResult
                    new DHLRepository().MappingCourierPieceDetail(result, directBookingDetail, DirectShipmentid);
                }

                //Step3 : Save Package Label Tracking detail
                new DHLRepository().SaveTrackingDetail(directBookingDetail, result, DirectShipmentid);

                //Step4:  //Start downloading the images from UPS server and making PDF

                var count      = 1;
                var totalpiece = result.PieceTrackingDetails.Count();
                totalpiece = totalpiece - 1;
                foreach (var data in result.PieceTrackingDetails.Take(totalpiece))
                {
                    if (directBookingDetail.CustomerRateCard.CourierName == FrayteCourierCompany.DHL)
                    {
                        _log.Error("downloading shipment image");
                        //Step3.1
                        data.LabelName = new DHLRepository().DownloadDHLImage(data, totalpiece, count, DirectShipmentid);
                        _log.Error("downloaded shipment image");
                    }

                    //// Step3.2
                    //new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    //_log.Error("saved package detail shipment image");
                    if (!data.PieceTrackingNumber.Contains("AirwayBillNumber_"))
                    {
                        // Step3.2
                        new DirectShipmentRepository().SavePackageDetail(data, result.CourierName);
                    }
                    count++;
                }
                var CourierPieceDetail = result.PieceTrackingDetails.Where(t => t.PieceTrackingNumber.Contains("AirwayBillNumber_")).FirstOrDefault();
                if (CourierPieceDetail != null)
                {
                    var data1 = new DHLRepository().DownloadDHLImage(CourierPieceDetail, totalpiece, 0, DirectShipmentid);
                }
                if (result != null)
                {
                    directBookingDetail.Error        = new FratyteError();
                    directBookingDetail.Error.Status = result.Status;
                }

                return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
            }
            else
            {
                directBookingDetail.Error = result.Error;
                new eCommerceUploadShipmentRepository().SaveBatchProcessUnprocessedShipment(1, directBookingDetail.CustomerId);
                //Send mail to developer
                new ShipmentEmailRepository().SendShipmentErrorMail(directBookingDetail, directBookingDetail.Error);
            }
            return(Tuple.Create(FR, directBookingDetail, DirectShipmentid));
        }