Beispiel #1
0
        public async Task <ActionResult> CancelOrderShipment([FromBody] SFOrderXMLRequest sFOrderXMLRequest)
        {
            //sFOrderXMLRequest.XMLMessage = "<Request service=\"OrderConfirmService\" lang=\"zh-CN\"><Head>LJ_T6NVV</Head><Body><OrderConfirm orderid=\"19066630505714563\" dealtype=\"2\"></OrderConfirm></Body></Request>";

            SFCancelOrderServiceRequest sFCancelOrderServiceRequest = new SFCancelOrderServiceRequest()
            {
                AccessNumber           = configuration["SFExpress:Access Number"],
                BaseURI                = configuration["SFExpress:Base URI"],
                Checkword              = configuration["SFExpress:Checkword"],
                RequestURI             = configuration["SFExpress:Cancel Order URI"],
                RequestOrderXMLMessage = sFOrderXMLRequest.XMLMessage,
            };

            GetSFCancelOrderServiceResponse getSFCancelOrderServiceResponse = QuincusService.SFExpressCancelOrder(sFCancelOrderServiceRequest);

            if (getSFCancelOrderServiceResponse.Response)
            {
                return(Ok(getSFCancelOrderServiceResponse.OrderResponse));
            }
            else
            {
                AuditEventEntry.WriteEntry(new Exception(getSFCancelOrderServiceResponse.exception.ToString()));
                return(Ok(getSFCancelOrderServiceResponse.exception));
            }
        }
        public async Task <ActionResult> CancelOrderShipment([FromBody] SFOrderXMLRequest sFOrderXMLRequest)
        {
            //sFOrderXMLRequest.XMLMessage = "<Request service=\"OrderConfirmService\" lang=\"zh-CN\"><Head>LJ_T6NVV</Head><Body><OrderConfirm orderid=\"19066630505714563\" dealtype=\"2\"></OrderConfirm></Body></Request>";

            SFCancelOrderServiceRequest sFCancelOrderServiceRequest = new SFCancelOrderServiceRequest()
            {
                AccessNumber           = configuration["SFExpress:Access Number"],
                BaseURI                = configuration["SFExpress:Base URI"],
                Checkword              = configuration["SFExpress:Checkword"],
                RequestURI             = configuration["SFExpress:Cancel Order URI"],
                RequestOrderXMLMessage = sFOrderXMLRequest.XMLMessage,
            };

            GetSFCancelOrderServiceResponse getSFCancelOrderServiceResponse = QuincusService.SFExpressCancelOrder(sFCancelOrderServiceRequest);

            if (getSFCancelOrderServiceResponse.Response)
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
                {
                    apiTypes       = UPS.DataObjects.LogData.APITypes.SFExpress,
                    apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 1),
                    dateTime       = System.DateTime.Now,
                    LogInformation = new UPS.DataObjects.LogData.LogInformation()
                    {
                        LogException = null,
                        LogRequest   = JsonConvert.SerializeObject(sFOrderXMLRequest),
                        LogResponse  = JsonConvert.SerializeObject(getSFCancelOrderServiceResponse)
                    }
                }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                return(Ok(getSFCancelOrderServiceResponse.OrderResponse));
            }
            else
            {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
                {
                    apiTypes       = UPS.DataObjects.LogData.APITypes.SFExpress,
                    apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 1),
                    dateTime       = System.DateTime.Now,
                    LogInformation = new UPS.DataObjects.LogData.LogInformation()
                    {
                        LogException = getSFCancelOrderServiceResponse.exception.InnerException.ToString(),
                        LogRequest   = JsonConvert.SerializeObject(sFOrderXMLRequest),
                        LogResponse  = null
                    }
                }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                //AuditEventEntry.WriteEntry(new Exception(getSFCancelOrderServiceResponse.exception.ToString()));
                return(Ok(getSFCancelOrderServiceResponse.exception));
            }
        }
        public async Task <ActionResult> UpdateShipmentCode([FromBody] ShipmentGeoCodes shipmentGeoCodes)
        {
            QuincusResponse quincusResponse = null;

            QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(new UPS.Quincus.APP.Configuration.QuincusParams()
            {
                endpoint = configuration["Quincus:TokenEndPoint"],
                password = configuration["Quincus:Password"],
                username = configuration["Quincus:UserName"],
            });

            if (quincusTokenDataResponse.ResponseStatus)
            {
                quincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest()
                {
                    endpoint         = configuration["Quincus:GeoCodeEndPoint"],
                    batchIDList      = shipmentGeoCodes.geoCode,
                    quincusTokenData = quincusTokenDataResponse.quincusTokenData
                });

                if (quincusResponse.ResponseStatus)
                {
                    if (quincusResponse.QuincusReponseData != null)
                    {
                        IList <Geocode> geocodes = quincusResponse.QuincusReponseData.geocode;

                        string TranslatedCode = geocodes[0].translated_adddress;

                        return(Ok(quincusResponse.QuincusReponseData));
                    }
                }
            }
            else
            {
                //AuditEventEntry.WriteEntry(new Exception(quincusTokenDataResponse.exception.ToString()));
                return(Ok(quincusTokenDataResponse.exception));
            }

            return(Ok("Error"));
        }
        public async Task <ActionResult> GetTranslationAddress([FromBody] List <ShipmentDataRequest> _shipmentDataRequest)
        {
            int wid = 0;

            if (_shipmentDataRequest.Any())
            {
                wid = _shipmentDataRequest.FirstOrDefault().WFL_ID;
            }
            QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse();
            QuincusParams quincusParams = new UPS.Quincus.APP.Configuration.QuincusParams()
            {
                endpoint  = configuration["Quincus:TokenEndPoint"],
                password  = configuration["Quincus:Password"],
                username  = configuration["Quincus:UserName"],
                chunkSize = int.TryParse(configuration["Quincus:BatchSize"], out int size) == true ? size : 10,
            };

            QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(quincusParams);

            if (quincusTokenDataResponse.ResponseStatus)
            {
                List <ShipmentWorkFlowRequest> shipmentWorkFlowRequests =
                    _shipmentDataRequest.Select(_ =>
                                                new ShipmentWorkFlowRequest()
                {
                    id         = _.ID,
                    rcV_ADR_TE = _.RCV_ADR_TE,
                    dsT_CTY_TE = _.DST_CTY_TE,
                    wfL_ID     = _.WFL_ID,
                    pkG_NR_TE  = _.PKG_NR_TE,
                    rcV_CPY_TE = _.RCV_CPY_TE,
                    dsT_PSL_TE = _.DST_PSL_TE
                }).ToList();

                this._quincusAddressTranslationRequest.shipmentWorkFlowRequests = shipmentWorkFlowRequests;
                this._quincusAddressTranslationRequest.token = quincusTokenDataResponse.quincusTokenData.token;

                quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(this._quincusAddressTranslationRequest, quincusParams);

                if (quincusTranslatedAddressResponse.Response)
                {
                    var getAddressTranslation = quincusTranslatedAddressResponse.ResponseData;

                    List <string> batchIds = new List <string>();

                    Dictionary <string, string> shipmentDetailsDictionary = new Dictionary <string, string>();
                    quincusTranslatedAddressResponse.ResponseData.ForEach(batches =>
                    {
                        batchIds.Add(batches.batch_id);

                        batches.addresses.ForEach(address =>
                        {
                            shipmentDetailsDictionary.Add(address.id, address.rcV_CPY_TE);
                        });
                    });

                    var QuincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest()
                    {
                        endpoint                  = configuration["Quincus:GeoCodeEndPoint"],
                        batchIDList               = batchIds,
                        quincusTokenData          = quincusTokenDataResponse.quincusTokenData,
                        ShipmentDetailsDictionary = shipmentDetailsDictionary
                    });

                    if (QuincusResponse.ResponseStatus)
                    {
                        // Insert Address into AddressBook
                        _addressBookService.InsertAddress(QuincusResponse.QuincusReponseDataList, shipmentDetailsDictionary);

                        try
                        {
                            var requestIds = _shipmentDataRequest.Select(_ => _.ID).ToList();
                            List <ShipmentDataRequest> existingShipmentDetails =
                                this._context.shipmentDataRequests
                                .Where(ShpDetail =>
                                       ShpDetail.WFL_ID == wid
                                       &&
                                       (ShpDetail.SMT_STA_NR == ((int)Enums.ATStatus.Uploaded)) &&
                                       (!requestIds.Contains(ShpDetail.ID))
                                       )
                                .ToList();


                            QuincusResponse.QuincusReponseDataList.ForEach(datalist =>
                            {
                                List <Geocode> geocodes = (List <Geocode>)((QuincusReponseData)datalist).geocode;
                                List <ShipmentDataRequest> shipmentDataRequestList = new List <ShipmentDataRequest>(geocodes.Count);

                                foreach (Geocode geocode in geocodes)
                                {
                                    ShipmentDataRequest currentShipmentDataRequest =
                                        _shipmentDataRequest.FirstOrDefault(_ => _.PKG_NR_TE == geocode.id);
                                    ShipmentDataRequest shipmentDataRequest = CreateShipmentAddressUpdateRequest(currentShipmentDataRequest, geocode);

                                    shipmentDataRequestList.Add(shipmentDataRequest);

                                    // Checking any same address are avaible, If there then updating those address also

                                    List <ShipmentDataRequest> sameAddressShpRequest =
                                        existingShipmentDetails.Where(
                                            (ShipmentDataRequest data) =>
                                            data.RCV_ADR_TE.ToLower().Replace(" ", "")
                                            .Equals(currentShipmentDataRequest.RCV_ADR_TE.ToLower().Replace(" ", ""))
                                            )
                                        .ToList();
                                    if (sameAddressShpRequest.Any())
                                    {
                                        sameAddressShpRequest.ForEach(shpDetails =>
                                        {
                                            var sameaddressRequest = CreateShipmentAddressUpdateRequest(shpDetails, geocode);
                                            shipmentDataRequestList.Add(sameaddressRequest);
                                        });
                                    }
                                }

                                shipmentDataRequestList = shipmentDataRequestList.GroupBy(x => x.ID).Select(x => x.First()).ToList();
                                _shipmentService.UpdateShipmentAddressByIds(shipmentDataRequestList);

                                //we need to update the workflow status
                                int?workflowstatus = _shipmentService.SelectShipmentTotalStatusByWorkflowId(wid);
                                WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest();
                                workflowDataRequest.ID         = wid;
                                workflowDataRequest.WFL_STA_TE = workflowstatus;
                                _workflowService.UpdateWorkflowStatusById(workflowDataRequest);
                            });
                        }
                        catch (Exception exception)
                        {
                            AuditEventEntry.WriteEntry(exception);
                        }



#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
                        {
                            apiTypes       = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation,
                            apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4),
                            dateTime       = System.DateTime.Now,
                            LogInformation = new UPS.DataObjects.LogData.LogInformation()
                            {
                                LogException = null,
                                LogRequest   = quincusTranslatedAddressResponse.QuincusContentRequest,
                                LogResponse  = JsonConvert.SerializeObject(QuincusResponse.QuincusReponseDataList)
                            }
                        }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                        return(Ok(QuincusResponse.QuincusReponseDataList));
                    }
                    else
                    {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
                        {
                            apiTypes       = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation,
                            apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4),
                            dateTime       = System.DateTime.Now,
                            LogInformation = new UPS.DataObjects.LogData.LogInformation()
                            {
                                LogException = QuincusResponse.Exception.InnerException.ToString(),
                                LogRequest   = quincusTranslatedAddressResponse.QuincusContentRequest,
                                LogResponse  = null
                            }
                        }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        return(Ok(QuincusResponse.Exception));
                    }
                }
                else
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
                    {
                        apiTypes       = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation,
                        apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4),
                        dateTime       = System.DateTime.Now,
                        LogInformation = new UPS.DataObjects.LogData.LogInformation()
                        {
                            LogException = quincusTranslatedAddressResponse.exception.InnerException.ToString(),
                            LogRequest   = JsonConvert.SerializeObject(_shipmentDataRequest),
                            LogResponse  = null
                        }
                    }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    return(Ok(quincusTranslatedAddressResponse.exception));
                }
            }
            else
            {
                return(Ok(quincusTokenDataResponse.exception));
            }
        }
        public async Task <ActionResult> CreateOrderShipment([FromBody] List <UIOrderRequestBodyData> uIOrderRequestBodyDatas)
        {
            string customerID = uIOrderRequestBodyDatas[0].spC_CST_ID_TE;//_shipmentService.GetShipmentCustomCodesInformation().CST_ID;

            _workflowID = uIOrderRequestBodyDatas[0].wfL_ID;
            CreateOrderShipmentResponse createOrderShipmentResponse = new CreateOrderShipmentResponse();

            createOrderShipmentResponse.FailedToProcessShipments = new List <string>();
            createOrderShipmentResponse.ProcessedShipments       = new List <string>();
            //ShipmentService shipmentService = new ShipmentService();

            //List<UIOrderRequestBodyData> uIOrderRequestBodyDatas = new List<UIOrderRequestBodyData>();

            foreach (var orderRequest in uIOrderRequestBodyDatas)
            {
                string XMLMessage = string.Empty;

                XMLMessage  = "<Request lang=\"zh-CN\" service=\"OrderService\">";
                XMLMessage += "<Head>" + configuration["SFExpress:Access Number"] + "</Head>";
                XMLMessage += "<Body>";
                XMLMessage += "<Order orderid=\"" + orderRequest.pkG_NR_TE + "\" custid=\"" + orderRequest.spC_CST_ID_TE + "\"";
                XMLMessage += " parcel_quantity=\"" + orderRequest.pcS_QTY_NR + "\"";
                XMLMessage += " total_net_weight=\"" + orderRequest.pkG_WGT_DE + "\"";
                XMLMessage += " j_company=\"" + orderRequest.shP_CPY_NA.ampReplacment() + "\"";
                XMLMessage += " j_address=\"" + orderRequest.shP_ADR_TE.ampReplacment() + "\"";
                XMLMessage += " j_city=\"" + orderRequest.orG_CTY_TE.ampReplacment() + "\"";
                XMLMessage += " j_post_code=\"" + orderRequest.orG_PSL_CD + "\"";
                XMLMessage += " j_contact=\"" + orderRequest.shP_CTC_TE.ampReplacment() + "\"";
                XMLMessage += " j_tel=\"" + orderRequest.shP_PH_TE + "\"";
                XMLMessage += " d_company=\"" + orderRequest.rcV_CPY_TE.ampReplacment() + "\"";
                XMLMessage += " d_city=\"" + orderRequest.dsT_CTY_TE.ampReplacment() + "\"";
                XMLMessage += " d_post_code=\"" + orderRequest.dsT_PSL_TE + "\"";
                XMLMessage += " d_contact=\"" + orderRequest.csG_CTC_TE.ampReplacment() + "\"";
                XMLMessage += " d_tel=\"" + orderRequest.pH_NR + "\"";
                XMLMessage += " specifications=\"" + orderRequest.fsT_INV_LN_DES_TE + "\"";
                XMLMessage += " routelabelService=\"1\"";
                XMLMessage += " d_address=\"" + orderRequest.shP_ADR_TR_TE + "\" cargo_total_weight=\"" + orderRequest.pkG_WGT_DE + "\"";
                XMLMessage += " pay_method=\"1\" is_docall=\"" + 0 + "\" need_return_tracking_no=\"" + orderRequest.poD_RTN_SVC + "\" express_type=\"6\"";
                XMLMessage += " >";
                XMLMessage += " </Order>";
                if (!string.IsNullOrEmpty(orderRequest.coD_TE))
                {
                    XMLMessage += "<AddedService name='COD' value=\"" + orderRequest.coD_TE + "\"></AddedService>";
                }
                XMLMessage += "</Body></Request>";


                SFCreateOrderServiceRequest sFCreateOrderServiceRequest = new SFCreateOrderServiceRequest()
                {
                    AccessNumber           = configuration["SFExpress:Access Number"],
                    BaseURI                = configuration["SFExpress:Base URI"],
                    Checkword              = configuration["SFExpress:Checkword"],
                    RequestURI             = configuration["SFExpress:Place Order URI"],
                    Checkcode              = configuration["SFExpress:CheckCode"],
                    RequestOrderXMLMessage = XMLMessage,
                };

                GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = QuincusService.SFExpressCreateOrder(sFCreateOrderServiceRequest);

                //shipmentDataResponse = shipmentService.UpdateShipmentStatusById(shipmentDataRequest);
                //if (!shipmentDataResponse.Success)
                //{
                //    AuditEventEntry.WriteEntry(new Exception(shipmentDataResponse.OperationExceptionMsg));
                //}

                if (getSFCreateOrderServiceResponse.Response)
                {
                    XmlDocument xmlDocumentShipmentResponse = new XmlDocument();
                    xmlDocumentShipmentResponse.LoadXml(getSFCreateOrderServiceResponse.OrderResponse);

                    string xmlDocumentShipmentResponseParser = xmlDocumentShipmentResponse.InnerXml;

                    if (xmlDocumentShipmentResponseParser.Contains("<ERROR"))
                    {
                        XmlDocument xmlDocument = new XmlDocument();

                        xmlDocument.LoadXml(getSFCreateOrderServiceResponse.OrderResponse);

                        //if (xmlDocumentShipmentResponseParser.Contains("8019"))
                        //{
                        //    createOrderShipmentResponse.FailedToProcessShipments.Add("Customer order number(" + orderRequest.pkG_NR_TE + ") is already confirmed");
                        //}
                        //else if (xmlDocumentShipmentResponseParser.Contains("8016"))
                        //{
                        //    createOrderShipmentResponse.FailedToProcessShipments.Add("Repeat order numbers ( " + orderRequest.pkG_NR_TE + " )");
                        //}
                        //else
                        //{
                        createOrderShipmentResponse.FailedToProcessShipments.Add(
                            string.Format("{0}:{1}:{2}",
                                          orderRequest.pkG_NR_TE,
                                          xmlDocument.GetElementsByTagName("ERROR")[0].Attributes[0].InnerText,
                                          xmlDocument.GetElementsByTagName("ERROR")[0].InnerXml));
                        //}
                    }
                    else
                    {
                        createOrderShipmentResponse.ProcessedShipments.Add(orderRequest.pkG_NR_TE);

                        ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest();
                        shipmentDataRequest.ID         = orderRequest.id;
                        shipmentDataRequest.WFL_ID     = orderRequest.wfL_ID;
                        shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Completed);
                        shipmentDataRequest.SMT_STA_TE = "Completed";
                        _workflowID = orderRequest.wfL_ID;

                        _shipmentService.UpdateShipmentStatusById(shipmentDataRequest);
                    }

                    createOrderShipmentResponse.Response = true;
                }
                else
                {
                    createOrderShipmentResponse.Response = false;
                }
            }
            //we need to update the workflow status
            int?                workflowstatus      = _shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID);
            WorkflowService     workflowService     = new WorkflowService(_context, _addressBookService, _entityValidationService);
            WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest();

            workflowDataRequest.ID         = _workflowID;
            workflowDataRequest.WFL_STA_TE = workflowstatus;
            workflowService.UpdateWorkflowStatusById(workflowDataRequest);



            await iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel()
            {
                apiTypes       = UPS.DataObjects.LogData.APITypes.SFExpress,
                apiType        = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 1),
                dateTime       = System.DateTime.Now,
                LogInformation = new UPS.DataObjects.LogData.LogInformation()
                {
                    LogException = null,
                    LogRequest   = JsonConvert.SerializeObject(uIOrderRequestBodyDatas),
                    LogResponse  = JsonConvert.SerializeObject(createOrderShipmentResponse)
                }
            });

            return(Ok(createOrderShipmentResponse));
        }
Beispiel #6
0
        public async Task <ActionResult> GetTranslationAddress([FromBody] List <ShipmentWorkFlowRequest> shipmentWorkFlowRequest)
        {
            int     wid          = 0;
            decimal requestCount = 0m;

            if (shipmentWorkFlowRequest.Any())
            {
                wid = shipmentWorkFlowRequest.FirstOrDefault().wfL_ID;
            }
            QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse();

            QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(new UPS.Quincus.APP.Configuration.QuincusParams()
            {
                endpoint = configuration["Quincus:TokenEndPoint"],
                password = configuration["Quincus:Password"],
                username = configuration["Quincus:UserName"],
            });

            if (quincusTokenDataResponse.ResponseStatus)
            {
                //quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(new UPS.Quincus.APP.Request.QuincusAddressTranslationRequest()
                //{
                //    endpoint = configuration["Quincus:GeoCodeEndPoint"],
                //    shipmentWorkFlowRequests = shipmentWorkFlowRequest,
                //    token = quincusTokenDataResponse.quincusTokenData.token
                //});
                this._quincusAddressTranslationRequest.shipmentWorkFlowRequests = shipmentWorkFlowRequest;
                this._quincusAddressTranslationRequest.token = quincusTokenDataResponse.quincusTokenData.token;

                List <List <ShipmentWorkFlowRequest> > shipmentWorkFlowRequests = new List <List <ShipmentWorkFlowRequest> >();
                shipmentWorkFlowRequests = QuincusProxy.ChunkBy(shipmentWorkFlowRequest, 20);

                foreach (List <ShipmentWorkFlowRequest> requests in shipmentWorkFlowRequests)
                {
                    requestCount = requests.Count();

                    quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(this._quincusAddressTranslationRequest);

                    if (quincusTranslatedAddressResponse.Response)
                    {
                        //return Ok(quincusTranslatedAddressResponse.ResponseData);

                        var getAddressTranslation = quincusTranslatedAddressResponse.ResponseData;

                        var QuincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest()
                        {
                            endpoint         = configuration["Quincus:GeoCodeEndPoint"],
                            id               = quincusTranslatedAddressResponse.ResponseData.batch_id,
                            quincusTokenData = quincusTokenDataResponse.quincusTokenData
                        }, requestCount);

                        if (QuincusResponse.ResponseStatus)
                        {
                            ShipmentDataRequest        shipment             = new ShipmentDataRequest();
                            List <Geocode>             geocodes             = (List <Geocode>)((QuincusReponseData)QuincusResponse.QuincusReponseData).geocode;
                            List <ShipmentDataRequest> shipmentsDataRequest = new List <ShipmentDataRequest>(geocodes.Count);
                            for (int i = 0; i < geocodes.Count; i++)
                            {
                                ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest();
                                shipmentDataRequest.ID            = Convert.ToInt32(geocodes[i].id);
                                shipmentDataRequest.WFL_ID        = wid;
                                shipmentDataRequest.SHP_ADR_TR_TE = geocodes[i].translated_adddress;
                                shipmentDataRequest.ACY_TE        = geocodes[i].accuracy;
                                shipmentDataRequest.CON_NR        = geocodes[i].confidence;

                                if (
                                    !string.IsNullOrEmpty(geocodes[i].translated_adddress)
                                    //&&  geocodes[i].translated_adddress != "NA"
                                    //&& !string.Equals(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().rcV_ADR_TE.Trim(),
                                    //    geocodes[i].translated_adddress.Trim())
                                    )
                                {
                                    shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Translated);
                                    shipmentDataRequest.SMT_STA_TE = "Translated";
                                }
                                else
                                {
                                    shipmentDataRequest.SMT_STA_NR = Convert.ToInt32(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().smT_STA_NR);
                                    shipmentDataRequest.SMT_STA_TE = Convert.ToString(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().smT_STA_TE);
                                }
                                shipmentsDataRequest.Add(shipmentDataRequest);
                            }
                            ShipmentService shipmentService = new ShipmentService();
                            shipmentService.UpdateShipmentAddressByIds(shipmentsDataRequest);
                            _workflowID = shipmentsDataRequest.FirstOrDefault().WFL_ID;
                            //we need to update the workflow status
                            int?workflowstatus = shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID);
                            WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest();
                            workflowDataRequest.ID         = _workflowID;
                            workflowDataRequest.WFL_STA_TE = workflowstatus;
                            workflowService.UpdateWorkflowStatusById(workflowDataRequest);
                        }
                        else
                        {
                            if (QuincusResponse.Exception == null)
                            {
                                AuditEventEntry.WriteEntry(new Exception("Translation failed..."));
                            }
                            else
                            {
                                AuditEventEntry.WriteEntry(new Exception(QuincusResponse.Exception.ToString()));
                            }
                            return(Ok(QuincusResponse?.Exception));
                        }
                    }
                    else
                    {
                        if (quincusTranslatedAddressResponse.exception == null)
                        {
                            AuditEventEntry.WriteEntry(new Exception("Translation failed..."));
                        }
                        else
                        {
                            AuditEventEntry.WriteEntry(new Exception(quincusTranslatedAddressResponse.exception.ToString()));
                        }
                        return(Ok(quincusTranslatedAddressResponse?.exception));
                    }
                }

                return(Ok(quincusTranslatedAddressResponse.ResponseData));
            }
            else
            {
                if (quincusTokenDataResponse.exception == null)
                {
                    AuditEventEntry.WriteEntry(new Exception("Translation failed..."));
                }
                else
                {
                    AuditEventEntry.WriteEntry(new Exception(quincusTokenDataResponse.exception.ToString()));
                }
                return(Ok(quincusTokenDataResponse?.exception));
            }
        }
Beispiel #7
0
        public async Task <ActionResult> CreateOrderShipment([FromBody] List <UIOrderRequestBodyData> uIOrderRequestBodyDatas)
        {
            _workflowID = uIOrderRequestBodyDatas[0].wfL_ID;
            CreateOrderShipmentResponse createOrderShipmentResponse = new CreateOrderShipmentResponse();

            createOrderShipmentResponse.FailedToProcessShipments = new List <string>();
            createOrderShipmentResponse.ProcessedShipments       = new List <string>();
            ShipmentService shipmentService = new ShipmentService();

            //List<UIOrderRequestBodyData> uIOrderRequestBodyDatas = new List<UIOrderRequestBodyData>();

            foreach (var orderRequest in uIOrderRequestBodyDatas)
            {
                string XMLMessage = string.Empty;

                XMLMessage  = "<Request lang=\"zh-CN\" service=\"OrderService\">";
                XMLMessage += "<Head>LJ_T6NVV</Head>";
                XMLMessage += "<Body>";
                XMLMessage += "<Order orderid=\"" + orderRequest.pkG_NR_TE + "\" custid=\"" + 7551234567 + "\"";
                XMLMessage += " j_tel=\"" + orderRequest.shP_CTC_TE + "\"";
                XMLMessage += " j_address=\"" + orderRequest.shP_ADR_TE + "\"";
                XMLMessage += " d_tel=\"" + orderRequest.pH_NR + "\"";
                XMLMessage += " d_address=\"" + orderRequest.shP_ADR_TR_TE + "\" cargo_total_weight=\"" + orderRequest.pkG_WGT_DE + "\"";
                XMLMessage += " pay_method=\"1\" is_docall=\"" + 1 + "\" need_return_tracking_no=\"" + orderRequest.poD_RTN_SVC + "\" express_type=\"6\"";
                XMLMessage += " >";
                XMLMessage += " </Order></Body></Request>";


                SFCreateOrderServiceRequest sFCreateOrderServiceRequest = new SFCreateOrderServiceRequest()
                {
                    AccessNumber           = configuration["SFExpress:Access Number"],
                    BaseURI                = configuration["SFExpress:Base URI"],
                    Checkword              = configuration["SFExpress:Checkword"],
                    RequestURI             = configuration["SFExpress:Place Order URI"],
                    RequestOrderXMLMessage = XMLMessage,
                };

                GetSFCreateOrderServiceResponse getSFCreateOrderServiceResponse = QuincusService.SFExpressCreateOrder(sFCreateOrderServiceRequest);

                //shipmentDataResponse = shipmentService.UpdateShipmentStatusById(shipmentDataRequest);
                //if (!shipmentDataResponse.Success)
                //{
                //    AuditEventEntry.WriteEntry(new Exception(shipmentDataResponse.OperationExceptionMsg));
                //}

                if (getSFCreateOrderServiceResponse.Response)
                {
                    XmlDocument xmlDocumentShipmentResponse = new XmlDocument();
                    xmlDocumentShipmentResponse.LoadXml(getSFCreateOrderServiceResponse.OrderResponse);

                    string xmlDocumentShipmentResponseParser = xmlDocumentShipmentResponse.InnerXml;

                    if (xmlDocumentShipmentResponseParser.Contains("<ERROR"))
                    {
                        if (xmlDocumentShipmentResponseParser.Contains("8019"))
                        {
                            createOrderShipmentResponse.FailedToProcessShipments.Add("Customer order number(" + orderRequest.pkG_NR_TE + ") is already confirmed");
                        }
                        else if (xmlDocumentShipmentResponseParser.Contains("8016"))
                        {
                            createOrderShipmentResponse.FailedToProcessShipments.Add("Repeat order numbers ( " + orderRequest.pkG_NR_TE + " )");
                        }
                        else
                        {
                            createOrderShipmentResponse.FailedToProcessShipments.Add(orderRequest.pkG_NR_TE);
                        }
                    }
                    else
                    {
                        createOrderShipmentResponse.ProcessedShipments.Add(orderRequest.pkG_NR_TE);

                        ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest();
                        shipmentDataRequest.ID         = orderRequest.id;
                        shipmentDataRequest.WFL_ID     = orderRequest.wfL_ID;
                        shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Completed);
                        shipmentDataRequest.SMT_STA_TE = "Completed";
                        _workflowID = orderRequest.wfL_ID;

                        shipmentService.UpdateShipmentStatusById(shipmentDataRequest);
                    }

                    createOrderShipmentResponse.Response = true;
                }
                else
                {
                    createOrderShipmentResponse.Response = false;
                    if (getSFCreateOrderServiceResponse.exception != null)
                    {
                        AuditEventEntry.WriteEntry(new Exception(getSFCreateOrderServiceResponse.exception.ToString()));
                    }
                }
            }
            //we need to update the workflow status
            int?                workflowstatus      = shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID);
            WorkflowService     workflowService     = new WorkflowService();
            WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest();

            workflowDataRequest.ID         = _workflowID;
            workflowDataRequest.WFL_STA_TE = workflowstatus;
            workflowService.UpdateWorkflowStatusById(workflowDataRequest);
            return(Ok(createOrderShipmentResponse));
        }