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));
        }
Пример #2
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));
        }