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); }
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); }