public SkyPostalResponse CreateShipment(SkyPostalRequest skyPostalRequest, int ExpressId) { SkyPostalResponse respone = new SkyPostalResponse(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.SKYPOSTAL); string result = string.Empty; #region SKYPOSTaL API Login skyPostalRequest.user_info.user_code = Convert.ToInt32(logisticIntegration.AppId); skyPostalRequest.user_info.app_key = logisticIntegration.InetgrationKey; skyPostalRequest.user_info.user_key = logisticIntegration.UserName; var skyPostalJson = Newtonsoft.Json.JsonConvert.SerializeObject(skyPostalRequest); result = SkyPostalWebApi(logisticIntegration, skyPostalJson); try { respone = Newtonsoft.Json.JsonConvert.DeserializeObject <SkyPostalResponse>(result); } catch (Exception ex) { ex.ToString(); } return(respone); }
public EtowerResponseModel CreateShipment(List <ETowerRequestModel> request, int DirectShipmentDraftId) { EtowerResponseModel response = new EtowerResponseModel(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.ETOWER); string url = logisticIntegration.ServiceUrl + "/services/shipper/orders"; var shipmentRequestjson = JsonConvert.SerializeObject(request); var result = ETowerApiCalling(url, shipmentRequestjson, "Shipment"); response = Newtonsoft.Json.JsonConvert.DeserializeObject <EtowerResponseModel>(result); response.Request = shipmentRequestjson; response.Response = result; if (response.status == "Success") { LabelResponseModel label = new LabelResponseModel(); #region Label Dwonload var eTowerLableRequest = new EtowerLableRequest() { labelFormat = "PDF", labelType = 1, merged = false, packinglist = true, }; eTowerLableRequest.orderIds = new List <string>(); eTowerLableRequest.orderIds.Add(response.data[0].orderId); var labeljson = JsonConvert.SerializeObject(eTowerLableRequest); string Labelurl = logisticIntegration.ServiceUrl + "/services/shipper/labels"; var lableResponse = ETowerApiCalling(Labelurl, labeljson, "Label"); label = JsonConvert.DeserializeObject <LabelResponseModel>(lableResponse); if (label.status == "Success") { response.data[0].labelContent = label.data[0].labelContent; } else { //Label Error } #endregion } else { var EtowerError = JsonConvert.DeserializeObject <EtowerError>(result); } return(response); }
public USPSResponse CreateShipment(USPSRequest request, int ExpressId) { USPSResponse response = new USPSResponse(); FrayteLogisticIntegration logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.USPS); string res = string.Empty; request.header.key = logisticIntegration.InetgrationKey; request.header.version = logisticIntegration.AppVersion; var usps = Newtonsoft.Json.JsonConvert.SerializeObject(request); res = GetResponse(logisticIntegration, usps); response = JsonConvert.DeserializeObject <USPSResponse>(res); var error = JsonConvert.DeserializeObject <USPSError>(res); return(response); }
public BringResponseModel CreateShipment(BringRequestModel bringRequest, int DraftShipmentId, string ShipmentType) { BringResponseModel response = new BringResponseModel(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.BRING); //API Login var shipmentRequestjson = JsonConvert.SerializeObject(bringRequest); string result = string.Empty; try { result = CallBringApi(logisticIntegration, shipmentRequestjson); if (!string.IsNullOrWhiteSpace(result)) { response = Newtonsoft.Json.JsonConvert.DeserializeObject <BringResponseModel>(result); } else { var error = new Models.Bring.Error(); error.code = "There is something is error please contact to admin"; response.errors = new List <Models.Bring.Error>(); response.errors.Add(error); if (ShipmentType == FrayteShipmentServiceType.DirectBooking) { new DirectShipmentRepository().SaveEasyPostErrorObject("Bring-result:-" + @result, "Bring-ShipJSON:-" + shipmentRequestjson, DraftShipmentId); } } response.request = shipmentRequestjson; response.response = result; } catch (Exception ex) { var error = new Models.Bring.Error(); error.code = ex.InnerException.ToString(); response.errors.Add(error); if (ShipmentType == FrayteShipmentServiceType.DirectBooking) { new DirectShipmentRepository().SaveEasyPostErrorObject("Bring-result:-" + @result, "Bring-ShipJSON:-" + shipmentRequestjson, DraftShipmentId); } } return(response); }
public SkyPostalTrackingResponseModel SkyPostalTrackWebApiCalling(SkyPostalTrackingModel trackModel) { SkyPostalTrackingResponseModel result = new SkyPostalTrackingResponseModel(); string response = string.Empty; try { var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.SKYPOSTAL); var skyPostalJson = Newtonsoft.Json.JsonConvert.SerializeObject(trackModel); WebClient client = new WebClient(); client.UseDefaultCredentials = true; client.Credentials = CredentialCache.DefaultCredentials; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; SslProtocols _Tls12 = (SslProtocols)0x00000C00; SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12; ServicePointManager.SecurityProtocol = Tls12; response = client.UploadString(logisticIntegration.ServiceUrl, "POST", skyPostalJson); if (!string.IsNullOrWhiteSpace(response)) { result = Newtonsoft.Json.JsonConvert.DeserializeObject <SkyPostalTrackingResponseModel>(response); } else { result = null; } } catch (Exception ex) { result = null; } return(result); }
public string CreateXMLDPDCHLogin() { string xmlPath = string.Empty; try { var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.DPDCH); if (AppSettings.LabelSave == "") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; // _log.Error("if section" + xmlPath); } else { if (AppSettings.ShipmentCreatedFrom == "BATCH") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; //_log.Error("else section BATCH" + xmlPath); } else { // _log.Error("else section BATCH"); xmlPath = HttpContext.Current.Server.MapPath("~/UploadFiles/PDFGenerator/HTMLFile"); } } if (!Directory.Exists(xmlPath)) { Directory.CreateDirectory(xmlPath); } xmlPath = xmlPath + "/DPDCHLogin.xml"; //_log.Error(xmlPath); if (File.Exists(xmlPath)) { File.Delete(xmlPath); } XmlDocument xmlDoc = new XmlDocument(); // XML Declaration XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); string soapNSURI = "http://schemas.xmlsoap.org/soap/envelope/"; // Create the root element soapenv:Envelope XmlElement rootEnvelope = xmlDoc.CreateElement("soapenv:Envelope", soapNSURI); rootEnvelope.SetAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); rootEnvelope.SetAttribute("xmlns:ns", "http://dpd.com/common/service/types/LoginService/2.0"); xmlDoc.AppendChild(rootEnvelope); // Create soapenv:Header XmlElement headerNode = xmlDoc.CreateElement("soapenv:Header", soapNSURI); // Append soapenv:Header rootEnvelope.AppendChild(headerNode); XmlElement bodyNode = xmlDoc.CreateElement("soapenv:Body", soapNSURI); XmlElement getAuth = xmlDoc.CreateElement("ns:getAuth", "ns"); XmlElement usernameNode = xmlDoc.CreateElement("delisId"); usernameNode.AppendChild(xmlDoc.CreateTextNode(logisticIntegration.UserName.ToString())); XmlElement password = xmlDoc.CreateElement("password"); password.AppendChild(xmlDoc.CreateTextNode(logisticIntegration.Password.ToString())); XmlElement messageLanguage = xmlDoc.CreateElement("messageLanguage"); messageLanguage.AppendChild(xmlDoc.CreateTextNode("de_EN")); getAuth.AppendChild(usernameNode); getAuth.AppendChild(password); getAuth.AppendChild(messageLanguage); bodyNode.AppendChild(getAuth); rootEnvelope.AppendChild(bodyNode); xmlDoc.Save(xmlPath); return(xmlPath); } catch (Exception ex) { return(ex.Message); } }
public string CreateXMLDPDCH(DPDChRequestModel dPdChRequestModel) { string xmlPath = string.Empty; try { var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.DHL); if (AppSettings.LabelSave == "") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; // _log.Error("if section" + xmlPath); } else { if (AppSettings.ShipmentCreatedFrom == "BATCH") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; //_log.Error("else section BATCH" + xmlPath); } else { // _log.Error("else section BATCH"); xmlPath = HttpContext.Current.Server.MapPath("~/UploadFiles/PDFGenerator/HTMLFile"); } } if (!Directory.Exists(xmlPath)) { Directory.CreateDirectory(xmlPath); } xmlPath = xmlPath + "/DPDCHShipment.xml"; //_log.Error(xmlPath); if (File.Exists(xmlPath)) { File.Delete(xmlPath); } XmlDocument xmlDoc = new XmlDocument(); // XML Declaration XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); string soapNSURI = "http://schemas.xmlsoap.org/soap/envelope/"; // Create the root element soapenv:Envelope XmlElement rootEnvelope = xmlDoc.CreateElement("soapenv:Envelope", soapNSURI); rootEnvelope.SetAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/"); rootEnvelope.SetAttribute("xmlns:ns", "http://dpd.com/common/service/types/Authentication/2.0"); rootEnvelope.SetAttribute("xmlns:ns1", "http://dpd.com/common/service/types/ShipmentService/3.2"); xmlDoc.AppendChild(rootEnvelope); //#region soapenv:Header XmlElement headerNode = xmlDoc.CreateElement("soapenv:Header", soapNSURI); // Append soapenv:Header XmlElement authentication = xmlDoc.CreateElement("ns:authentication", "ns"); XmlElement usernameNode = xmlDoc.CreateElement("delisId"); usernameNode.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.UserName)); XmlElement authToken = xmlDoc.CreateElement("authToken"); authToken.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.AuthToken)); XmlElement messageLanguage = xmlDoc.CreateElement("messageLanguage"); messageLanguage.AppendChild(xmlDoc.CreateTextNode("de_EN")); authentication.AppendChild(usernameNode); authentication.AppendChild(authToken); authentication.AppendChild(messageLanguage); headerNode.AppendChild(authentication); rootEnvelope.AppendChild(headerNode); XmlElement bodyNode = xmlDoc.CreateElement("soapenv:Body", soapNSURI); XmlElement storeOrders = xmlDoc.CreateElement("ns1:storeOrders", "ns1"); XmlElement printOptions = xmlDoc.CreateElement("printOptions"); XmlElement printerLanguage = xmlDoc.CreateElement("printerLanguage"); printerLanguage.AppendChild(xmlDoc.CreateTextNode("PDF")); XmlElement paperFormat = xmlDoc.CreateElement("paperFormat"); paperFormat.AppendChild(xmlDoc.CreateTextNode("A6")); printOptions.AppendChild(printerLanguage); printOptions.AppendChild(paperFormat); XmlElement order = xmlDoc.CreateElement("order"); XmlElement generalShipmentData = xmlDoc.CreateElement("generalShipmentData"); XmlElement sendingDepot = xmlDoc.CreateElement("sendingDepot"); sendingDepot.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.SendingDepot)); XmlElement product = xmlDoc.CreateElement("product"); product.AppendChild(xmlDoc.CreateTextNode("CL")); XmlElement sender = xmlDoc.CreateElement("sender"); generalShipmentData.AppendChild(sendingDepot); generalShipmentData.AppendChild(product); XmlElement name1 = xmlDoc.CreateElement("name1"); name1.AppendChild(xmlDoc.CreateTextNode((dPdChRequestModel.Shipper.Company == null || dPdChRequestModel.Shipper.Company == "") ? dPdChRequestModel.Shipper.Contact : dPdChRequestModel.Shipper.Company)); XmlElement name2 = xmlDoc.CreateElement("name2"); name2.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Address1)); XmlElement street = xmlDoc.CreateElement("street"); street.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Address2)); XmlElement country = xmlDoc.CreateElement("country"); country.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Country)); XmlElement zipCode = xmlDoc.CreateElement("zipCode"); zipCode.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Postcode)); XmlElement city = xmlDoc.CreateElement("city"); city.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Town)); XmlElement phone = xmlDoc.CreateElement("phone"); phone.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Shipper.Telephone)); sender.AppendChild(name1); sender.AppendChild(name2); sender.AppendChild(street); sender.AppendChild(country); sender.AppendChild(zipCode); sender.AppendChild(city); sender.AppendChild(phone); XmlElement recipient = xmlDoc.CreateElement("recipient"); XmlElement recipientname = xmlDoc.CreateElement("name1"); recipientname.AppendChild(xmlDoc.CreateTextNode((dPdChRequestModel.Recipient.Company == null || dPdChRequestModel.Recipient.Company == "") ? dPdChRequestModel.Recipient.Contact : dPdChRequestModel.Recipient.Company)); XmlElement recipientname2 = xmlDoc.CreateElement("name2"); recipientname2.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Recipient.Address1)); XmlElement recipientstreet = xmlDoc.CreateElement("street"); recipientstreet.AppendChild(xmlDoc.CreateTextNode((dPdChRequestModel.Recipient.Address2 == null || dPdChRequestModel.Recipient.Address2 == "") ? dPdChRequestModel.Recipient.Address1 : dPdChRequestModel.Recipient.Address2)); XmlElement recipientcountry = xmlDoc.CreateElement("country"); recipientcountry.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Recipient.Country)); XmlElement recipientzipCode = xmlDoc.CreateElement("zipCode"); recipientzipCode.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Recipient.Postcode)); XmlElement recipientcity = xmlDoc.CreateElement("city"); recipientcity.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Recipient.Town)); XmlElement recipientphone = xmlDoc.CreateElement("phone"); recipientphone.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Recipient.Telephone)); recipient.AppendChild(recipientname); recipient.AppendChild(recipientname2); recipient.AppendChild(recipientstreet); recipient.AppendChild(recipientcountry); recipient.AppendChild(recipientzipCode); recipient.AppendChild(recipientcity); recipient.AppendChild(recipientphone); generalShipmentData.AppendChild(sender); generalShipmentData.AppendChild(recipient); order.AppendChild(generalShipmentData); for (int i = 0; i < dPdChRequestModel.Package.Count; i++) { XmlElement parcels = xmlDoc.CreateElement("parcels"); XmlElement customerReferenceNumber1 = xmlDoc.CreateElement("customerReferenceNumber1"); customerReferenceNumber1.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.ReferenceNumber1)); XmlElement weight = xmlDoc.CreateElement("weight"); weight.AppendChild(xmlDoc.CreateTextNode(dPdChRequestModel.Package[i].Weight)); parcels.AppendChild(customerReferenceNumber1); parcels.AppendChild(weight); order.AppendChild(parcels); } XmlElement productAndServiceData = xmlDoc.CreateElement("productAndServiceData"); XmlElement orderType = xmlDoc.CreateElement("orderType"); orderType.AppendChild(xmlDoc.CreateTextNode("consignment")); productAndServiceData.AppendChild(orderType); XmlElement predict = xmlDoc.CreateElement("predict"); XmlElement channel = xmlDoc.CreateElement("channel"); channel.AppendChild(xmlDoc.CreateTextNode("1")); XmlElement value = xmlDoc.CreateElement("value"); value.AppendChild(xmlDoc.CreateTextNode("*****@*****.**")); XmlElement language = xmlDoc.CreateElement("language"); language.AppendChild(xmlDoc.CreateTextNode("EN")); predict.AppendChild(channel); predict.AppendChild(value); predict.AppendChild(language); productAndServiceData.AppendChild(predict); order.AppendChild(productAndServiceData); storeOrders.AppendChild(printOptions); storeOrders.AppendChild(order); bodyNode.AppendChild(storeOrders); rootEnvelope.AppendChild(bodyNode); xmlDoc.Save(xmlPath); return(xmlPath); } catch (Exception ex) { return(ex.Message); } }
public DPDChResponseModel CreateShipment(DPDChRequestModel dpdChRequest, string ShipmentType) { DPDChResponseModel response = new DPDChResponseModel(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.DPDCH); //API Login string ApiShipment = string.Empty; string xml_ship = string.Empty; string xml_in = string.Empty; string ApiLogin = string.Empty; try { #region API Login string XMLDPDCHLogin = CreateXMLDPDCHLogin(); xml_in = File.ReadAllText(@XMLDPDCHLogin); var kk = "xmlns:ns=\"ns\""; xml_in = xml_in.Replace(kk, ""); ApiLogin = CallWebservice(xml_in, logisticIntegration.LabelApiUrl); var result = XDocument.Parse(ApiLogin); if (!string.IsNullOrWhiteSpace(ApiLogin) && !ApiLogin.Contains("soap:Fault")) { var loginResult = (from r in result.Descendants("return") select new { delisId = r.Element("delisId") != null ? r.Element("delisId").Value : "", authToken = r.Element("authToken") != null ? r.Element("authToken").Value : "", depot = r.Element("depot") != null ? r.Element("depot").Value : "" }).FirstOrDefault(); dpdChRequest.AuthToken = loginResult.authToken; dpdChRequest.UserName = loginResult.delisId; dpdChRequest.SendingDepot = loginResult.depot; } else { var xml = XDocument.Parse(@ApiLogin); var Error = (from r in xml.Descendants("detail") select new { code = r.Element("errorCode") != null ? r.Element("errorCode").Value : "", message = r.Element("ConditionData") != null ? r.Element("ConditionData").Value : "", }).ToList(); response.Status = false; response.Error = new FratyteError(); response.Error.Service = new List <string>(); foreach (var i in Error) { string err = string.Empty; err = i.code + "-" + i.message; response.Error.ServiceError.Add(err); } if (ShipmentType == FrayteShipmentServiceType.DirectBooking) { new DirectShipmentRepository().SaveEasyPostErrorObject(@ApiLogin, xml_in, dpdChRequest.DraftShipmentId); } } #endregion #region Order Insert if (logisticIntegration != null && !string.IsNullOrWhiteSpace(dpdChRequest.AuthToken)) { string xml_path = CreateXMLDPDCH(dpdChRequest); xml_ship = File.ReadAllText(@xml_path); var ns = "xmlns:ns=\"ns\""; xml_ship = xml_ship.Replace(ns, ""); var ns1 = "xmlns:ns1=\"ns1\""; xml_ship = xml_ship.Replace(ns1, ""); response.Request = xml_ship; ApiShipment = CallWebservice(xml_ship, logisticIntegration.ServiceUrl); response.Response = @ApiShipment; var ApiShipmentresult = XDocument.Parse(ApiShipment); if (!string.IsNullOrWhiteSpace(ApiShipment) && !ApiLogin.Contains("soap:Fault") && !ApiShipment.Contains("faults")) { var parcellabelsPDF = (from r in ApiShipmentresult.Descendants("orderResult") select new { parcellabelsPDF = r.Element("parcellabelsPDF") != null ? r.Element("parcellabelsPDF").Value : "", }).FirstOrDefault(); var shipmentResponses = (from r in ApiShipmentresult.Descendants("shipmentResponses") select new { mpsId = r.Element("mpsId") != null ? r.Element("mpsId").Value : "", }).FirstOrDefault(); var parcelInformation = (from r in ApiShipmentresult.Descendants("parcelInformation") select new { parcelLabelNumber = r.Element("parcelLabelNumber") != null ? r.Element("parcelLabelNumber").Value : "", }).ToList(); response.ParcelLabelPDF = parcellabelsPDF.parcellabelsPDF; response.ShipmentResponses = new ShipmentResponse(); response.ShipmentResponses.mpsId = shipmentResponses.mpsId; response.ShipmentResponses.ParcelLabelNumber = new List <string>(); foreach (var Label in parcelInformation) { response.ShipmentResponses.ParcelLabelNumber.Add(Label.parcelLabelNumber); } } else { var xml = XDocument.Parse(@ApiShipment); var Error = (from r in xml.Descendants("faults") select new { code = r.Element("faultCode") != null ? r.Element("faultCode").Value : "", message = r.Element("message") != null ? r.Element("message").Value : "", }).ToList(); response.Status = false; response.Error = new FratyteError(); response.Error.Service = new List <string>(); foreach (var i in Error) { string err = string.Empty; err = i.code + "-" + i.message; response.Error.Service.Add(err); } if (ShipmentType == FrayteShipmentServiceType.DirectBooking) { new DirectShipmentRepository().SaveEasyPostErrorObject(@ApiShipment, xml_ship, dpdChRequest.DraftShipmentId); } } } else { var xml = XDocument.Parse(@ApiLogin); var Error = (from r in xml.Descendants("soap:Fault") select new { code = r.Element("faultcode") != null ? r.Element("faultcode").Value : "", message = r.Element("faultstring") != null ? r.Element("faultstring").Value : "", }).ToList(); response.Status = false; response.Error = new FratyteError(); response.Error.Service = new List <string>(); foreach (var i in Error) { string err = string.Empty; err = i.code + "-" + i.message; response.Error.Service.Add(err); } if (ShipmentType == FrayteShipmentServiceType.DirectBooking) { new DirectShipmentRepository().SaveEasyPostErrorObject(@ApiShipment, xml_ship, dpdChRequest.DraftShipmentId); } } #endregion } catch (Exception ex) { response.Status = false; response.Error = new FratyteError(); response.Error.Miscellaneous = new List <string>(); response.Error.Miscellaneous.Add((ex.InnerException != null ? ex.InnerException.ToString() : ex.Message.ToString())); new DirectShipmentRepository().SaveEasyPostErrorObject("DPD-CHShipmentResult:-" + @ApiShipment + "DPD-CH API LoginResult:-" + @ApiLogin, "DPDCH-ShipXML:-" + xml_ship + "DPDCH-LoginXMl:-" + xml_in, dpdChRequest.DraftShipmentId); } return(response); }
public EAMGlobalResponse CreateShipment(string shipmentXml, int DraftShipmentId) { EAMGlobalResponse response = new EAMGlobalResponse(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.EAM); if (logisticIntegration != null) { string serverUrl = logisticIntegration.ServiceUrl; string trackingCode = string.Empty; var shipmentPackageTrackingDetail = new List <FraytePackageTrackingDetail>(); //Send XML var shipmentResult = CallWebservice(shipmentXml, serverUrl); //utf-8 only try { var xmltag = "<?xml version=" + "'1.0'" + " encoding=" + "'UTF-8'" + " ?>"; shipmentResult = xmltag + @shipmentResult; var result = XDocument.Parse(shipmentResult); if (!string.IsNullOrWhiteSpace(shipmentResult) && !shipmentResult.Contains("ERROR")) { var label = (from r in result.Descendants("LABEL") select new { Lable = r.Element("LINK") != null ? r.Element("LINK").Value : "", AWB = r.Element("AWB") != null ? r.Element("AWB").Value : "" }).FirstOrDefault(); response.LabelUrl = label.Lable; response.Status = true; response.AWB = label.AWB; } else { var pickupxml = XDocument.Parse(shipmentResult); var ElementsList = pickupxml.Descendants("MESSAGE") .Select(x => new { ElementContent = x.Value }) .ToList(); response.ERROR = new List <string>(); foreach (var message in ElementsList) { response.ERROR.Add(message.ElementContent); } new DirectShipmentRepository().SaveEasyPosyPickUpObject(@shipmentResult, shipmentXml, DraftShipmentId); } } catch (Exception ex) { var pickupxml = XDocument.Parse(shipmentResult); var Error = (from r in pickupxml.Descendants("Condition") select new { ErrorCode = r.Element("ConditionCode") != null ? r.Element("ConditionCode").Value : "", ErrorDescription = r.Element("ConditionData") != null ? r.Element("ConditionData").Value : "", }).ToList(); new DirectShipmentRepository().SaveEasyPosyPickUpObject(@shipmentResult, shipmentXml, DraftShipmentId); } } return(response); }
public string CreateXMLForEAM(EAMRequestModel eamRequest) { string xmlPath = string.Empty; try { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings(); xmlWriterSettings.Encoding = new UTF8Encoding(true); xmlWriterSettings.ConformanceLevel = ConformanceLevel.Document; xmlWriterSettings.Indent = true; var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.EAM); eamRequest.Account = logisticIntegration.UserName; eamRequest.Password = logisticIntegration.Password; //xmlPath = It will be the path where xml will saved if (AppSettings.LabelSave == "") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; } else { if (AppSettings.ShipmentCreatedFrom == "BATCH") { xmlPath = AppSettings.WebApiPath + "/UploadFiles/PDFGenerator/HTMLFile"; } else { // _log.Error("else section BATCH"); xmlPath = HttpContext.Current.Server.MapPath("~/UploadFiles/PDFGenerator/HTMLFile"); } } if (!Directory.Exists(xmlPath)) { Directory.CreateDirectory(xmlPath); } xmlPath = xmlPath + "/EAMShipment.xml"; if (File.Exists(xmlPath)) { File.Delete(xmlPath); } using (var xmlWriter = XmlWriter.Create(xmlPath)) { xmlWriter.WriteStartDocument(); if (logisticIntegration != null) { xmlWriter.WriteStartElement("ProcessShipmentRequest"); xmlWriter.WriteStartElement("WebAuthenticationDetail"); xmlWriter.WriteStartElement("UserCredential"); xmlWriter.WriteStartElement("Account"); xmlWriter.WriteString(eamRequest.Account); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Password"); xmlWriter.WriteString(eamRequest.Password); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("TransactionDetail"); xmlWriter.WriteStartElement("CustomerTransactionId"); xmlWriter.WriteString(eamRequest.CustomerTransactionId); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("RequestedShipment"); xmlWriter.WriteStartElement("ShipperCompany"); xmlWriter.WriteString(eamRequest.ShipperCompany); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperContact"); xmlWriter.WriteString(eamRequest.ShipperContact); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperAddress1"); xmlWriter.WriteString(eamRequest.ShipperAddress1); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperAddress2"); xmlWriter.WriteString(string.IsNullOrEmpty(eamRequest.ShipperAddress2) ? "." : eamRequest.ShipperAddress2); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperAddress3"); xmlWriter.WriteString(eamRequest.ShipperAddress3); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperTown"); xmlWriter.WriteString(eamRequest.ShipperTown); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperCountry"); xmlWriter.WriteString(eamRequest.ShipperCountry); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperPostcode"); xmlWriter.WriteString(string.IsNullOrEmpty(eamRequest.ShipperPostcode) ? "" : eamRequest.ShipperPostcode.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("ShipperTelephone"); xmlWriter.WriteString(eamRequest.ShipperTelephone); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Hawb"); xmlWriter.WriteString(eamRequest.Hawb); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Service"); xmlWriter.WriteString(eamRequest.Service); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Mawb"); xmlWriter.WriteString(eamRequest.Mawb); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Date"); xmlWriter.WriteString(eamRequest.Date.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Company"); xmlWriter.WriteString(eamRequest.Company); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Contact"); xmlWriter.WriteString(eamRequest.Contact); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Address1"); xmlWriter.WriteString(eamRequest.Address1); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Address2"); xmlWriter.WriteString(string.IsNullOrEmpty(eamRequest.Address2) ? "'.'" : eamRequest.Address2); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Address3"); xmlWriter.WriteString(eamRequest.Address3); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Town"); xmlWriter.WriteString(eamRequest.Town); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Country"); xmlWriter.WriteString(eamRequest.Country); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Postcode"); xmlWriter.WriteString(string.IsNullOrEmpty(eamRequest.Postcode) ? "" : eamRequest.Postcode); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("telephone"); xmlWriter.WriteString(eamRequest.telephone.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("noOfPieces"); xmlWriter.WriteString(eamRequest.noOfPieces); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Weight"); xmlWriter.WriteString(eamRequest.Weight.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("DoxNonDox"); xmlWriter.WriteString(eamRequest.DoxNonDox.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Description"); xmlWriter.WriteString(eamRequest.Description); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Value"); xmlWriter.WriteString(eamRequest.Value); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Weight"); xmlWriter.WriteString(eamRequest.Weight.ToString()); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Currency"); xmlWriter.WriteString(eamRequest.Currency); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Agent"); xmlWriter.WriteString(eamRequest.Agent); xmlWriter.WriteEndElement(); xmlWriter.WriteStartElement("Notes"); xmlWriter.WriteString(eamRequest.Notes); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); } return(xmlPath); } } catch (Exception ex) { return(ex.Message); } }
public DpdShipmentResponse CreateShipment(DPDRequestModel dpdRequestObj) { DpdShipmentResponse respone = new DpdShipmentResponse(); var logisticIntegration = UtilityRepository.getLogisticIntegration(UtilityRepository.GetOperationZone().OperationZoneId, AppSettings.ApplicationMode, FrayteIntegration.DPD); string result = string.Empty; var abc = Newtonsoft.Json.JsonConvert.SerializeObject(dpdRequestObj); #region DPD API Login string usernamePasswordBase64String = Base64Encode(logisticIntegration.UserName + ":" + logisticIntegration.Password); //Api Login string loginRespone = LogindpdWebApi(logisticIntegration, usernamePasswordBase64String); var DPDLogin = Newtonsoft.Json.JsonConvert.DeserializeObject <DPDLoginResponeModel>(loginRespone); if (DPDLogin.error == null) { var shipmentRequestjson = JsonConvert.SerializeObject(dpdRequestObj); //Insert Shipment string shipmentResponsejson = CallDpdWebApi(logisticIntegration, shipmentRequestjson, DPDLogin.data.geoSession); respone.DPDResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <DPDResponseModel>(shipmentResponsejson); if (respone.DPDResponse.error == null) { //Get Label respone.LabelHTMLString = CallDpdLabelApi(logisticIntegration, respone.DPDResponse.data.shipmentId, DPDLogin.data.geoSession, "text/html"); respone.LabeleplString = CallDpdLabelApi(logisticIntegration, respone.DPDResponse.data.shipmentId, DPDLogin.data.geoSession, "text/vnd.eltron-epl"); //Collection Pickup return(respone); } else { respone.Error = new FratyteError(); respone.Error.Service = new List <string>(); string err = string.Empty; foreach (var error in respone.DPDResponse.error) { err += error.Obj + " - " + error.errorMessage + ","; } respone.Error.Service.Add(err); respone.Error.Status = false; //Error Recorded SaveDirectShipmentObject(shipmentRequestjson, respone.DPDResponse.error.ToString(), dpdRequestObj.DraftShipmentId); } } else { respone.Error = new FratyteError(); respone.Error.Service = new List <string>(); string err = string.Empty; foreach (var error in respone.DPDResponse.error) { err += error.Obj + " - " + error.errorMessage + ","; } respone.Error.Service.Add(err); respone.Error.Status = false; //Error Recorded SaveDirectShipmentObject(usernamePasswordBase64String, respone.DPDResponse.error.ToString(), dpdRequestObj.DraftShipmentId); } #endregion return(respone); }