public RxoBaseResponseEntity CallCheckOrder(RxoCheckOrderRequest modelCheckOrder)
        {
            int    iReturnFromResponse = 0;
            string soapResult          = "";


            ////////////////////////////////////
            //
            // ...config stuff
            //
            ////////////////////////////////////

            modelCheckOrder.ORIGIN_NAME = configRxoWs.ORIGIN_NAME;


            ////////////////////////////////////
            //
            // create the service response
            //
            ////////////////////////////////////

            RxoBaseResponseEntity responseCheckOrder = new RxoBaseResponseEntity();


            ////////////////////////////////////
            //
            // Prepare the SOAP Request
            //
            ////////////////////////////////////

            HttpWebRequest request = CreateWebRequest(configRxoWs);


            ////////////////////////////////////
            //
            // Prepare the SOAP Request
            //
            ////////////////////////////////////

            string stringRequest = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:rxo=""http://rxo.webservices.luxottica.it/""  xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
                                        <soapenv:Header/>
                                        <soapenv:Body>
                                           <rxo:rxoCheckOrder>
                                              <arg0 id=""{0}"">
                                                 <HEADER>	
                                                 <ORIGIN>
                                                    <NAME>{1}</NAME>
                                                 </ORIGIN>
                                                 <DATE_REQUESTED>{2}</DATE_REQUESTED>
                                                 <ACCOUNT class=""orderBy"">
                                                 <ACCOUNT_ID>{3}</ACCOUNT_ID>
                                                 </ACCOUNT>
                                                 <ACCOUNT class=""shipTo"">
                                                 <ACCOUNT_ID>{3}</ACCOUNT_ID>
                                                 </ACCOUNT>
                                                 <ACCOUNT class=""billTo"">
                                                 <ACCOUNT_ID>{3}</ACCOUNT_ID>
                                                 </ACCOUNT>
                                                 <PATIENT>
                                                 <FIRST_NAME>{4}</FIRST_NAME>
                                                 <LAST_NAME>{4}</LAST_NAME>
                                                 </PATIENT>
                                                 </HEADER> 
         
                                                 <LENS eye=""R"">
                                                    <SALES_ARTICLE>{5}</SALES_ARTICLE>
                                                    <SPHERE>{6}</SPHERE>
                                                    <CYLINDER>{7}</CYLINDER>
                                                    <AXIS>{8}</AXIS>
                                                    <PD>
                                                       <DISTANCE>{9}</DISTANCE>
                                                    </PD>
                                                    <ADD>{10}</ADD>
                                                    <SEG_HEIGHT xsi:nil=""true"">{11}</SEG_HEIGHT>
                                                    <OC_HEIGHT class=""Height"">{12}</OC_HEIGHT>
                                                    <OPC></OPC>
                                                 </LENS>

                                                 <LENS eye=""L"">
                                                    <SALES_ARTICLE>{5}</SALES_ARTICLE>
                                                    <SPHERE>{13}</SPHERE>
                                                    <CYLINDER>{14}</CYLINDER>
                                                    <AXIS>{15}</AXIS>
                                                    <PD>
                                                       <DISTANCE>{16}</DISTANCE>
                                                    </PD>
                                                    <ADD>{17}</ADD>
                                                    <SEG_HEIGHT xsi:nil=""true"">{18}</SEG_HEIGHT>
                                                    <OC_HEIGHT class=""Height"">{19}</OC_HEIGHT>
                                                    <OPC/>
                                                 </LENS>

                                                 <ITEMS>
                                                    <FRAME>
                                                       <UPC>{20}</UPC>
                                                       <DBL>{21}</DBL>
                                                    </FRAME>
                                                 </ITEMS>
                                              </arg0>
                                           </rxo:rxoCheckOrder>
                                        </soapenv:Body>
                                     </soapenv:Envelope>";


            stringRequest = stringRequest.Replace("{0}", modelCheckOrder.arg0);

            XDocument baseRequest = XDocument.Parse(stringRequest);

            //
            // Update <HEADER><ORIGIN><NAME>
            //
            IEnumerable <XElement> TagORIGIN = baseRequest.Descendants("ORIGIN");

            foreach (XElement _element in TagORIGIN)
            {
                if (_element.Name.LocalName == "ORIGIN")
                {
                    _element.Element("NAME").Value = modelCheckOrder.ORIGIN_NAME;
                }
            }

            //
            // Update <HEADER><DATE_REQUESTED>
            //
            IEnumerable <XElement> TagDATE_REQUESTED = baseRequest.Descendants("HEADER");

            foreach (XElement _element in TagDATE_REQUESTED)
            {
                if (_element.Name.LocalName == "HEADER")
                {
                    _element.Element("DATE_REQUESTED").Value = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }

            //
            // Update <HEADER><ORIGIN><ACCOUNT>
            //
            IEnumerable <XElement> TagACCOUNT = baseRequest.Descendants("ACCOUNT");

            foreach (XElement _element in TagACCOUNT)
            {
                if (_element.Name.LocalName == "ACCOUNT")
                {
                    _element.Element("ACCOUNT_ID").Value = modelCheckOrder.ACCOUNT;
                }
            }

            //
            // Update <HEADER><ORIGIN><PATIENT>
            //
            IEnumerable <XElement> TagPATIENT = baseRequest.Descendants("PATIENT");

            foreach (XElement _element in TagPATIENT)
            {
                if (_element.Name.LocalName == "PATIENT")
                {
                    _element.Element("FIRST_NAME").Value = modelCheckOrder.PATIENT_FIRST_NAME;
                    _element.Element("LAST_NAME").Value  = modelCheckOrder.PATIENT_LAST_NAME;
                }
            }

            //
            // Update <LENS ...>
            //
            IEnumerable <XElement> TagLENSR = baseRequest.Descendants("LENS");

            foreach (XElement _element in TagLENSR)
            {
                if (_element.Name.LocalName == "LENS")
                {
                    _element.Element("SALES_ARTICLE").Value = modelCheckOrder.LENS_SALES_ARTICLE;
                }

                if (_element.Name.LocalName == "LENS" && _element.FirstAttribute.Value == "R")
                {
                    _element.Element("SPHERE").Value   = modelCheckOrder.LENS_R_SPHERE;
                    _element.Element("CYLINDER").Value = modelCheckOrder.LENS_R_CYLINDER;
                    _element.Element("AXIS").Value     = modelCheckOrder.LENS_R_AXIS;

                    XElement subPD = _element.Element("PD");
                    subPD.Element("DISTANCE").Value = modelCheckOrder.LENS_R_DISTANCE;

                    if (modelCheckOrder.LENS_R_TYPE == "4")
                    {
                        // Progressive
                        _element.Element("ADD").Value        = modelCheckOrder.LENS_R_ADD;
                        _element.Element("SEG_HEIGHT").Value = modelCheckOrder.LENS_R_SEG_HEIGHT;
                        _element.Element("OC_HEIGHT").Value  = "";
                    }
                    else
                    {
                        // Single Vision
                        _element.Element("ADD").Value        = "";
                        _element.Element("SEG_HEIGHT").Value = "";
                        _element.Element("OC_HEIGHT").Value  = modelCheckOrder.LENS_R_OC_HEIGHT;
                    }
                }
                else
                {
                    _element.Element("SPHERE").Value   = modelCheckOrder.LENS_L_SPHERE;
                    _element.Element("CYLINDER").Value = modelCheckOrder.LENS_L_CYLINDER;
                    _element.Element("AXIS").Value     = modelCheckOrder.LENS_L_AXIS;

                    XElement subPD = _element.Element("PD");
                    subPD.Element("DISTANCE").Value = modelCheckOrder.LENS_L_DISTANCE;

                    if (modelCheckOrder.LENS_R_TYPE == "4")
                    {
                        // Progressive
                        _element.Element("ADD").Value        = modelCheckOrder.LENS_L_ADD;
                        _element.Element("SEG_HEIGHT").Value = modelCheckOrder.LENS_L_SEG_HEIGHT;
                        _element.Element("OC_HEIGHT").Value  = "";
                    }
                    else
                    {
                        // Single Vision
                        _element.Element("ADD").Value        = "";
                        _element.Element("SEG_HEIGHT").Value = "";
                        _element.Element("OC_HEIGHT").Value  = modelCheckOrder.LENS_L_OC_HEIGHT;
                    }
                }
            }

            //
            // Update <ITEMS><FRAME>
            //

            IEnumerable <XElement> TagFRAME = baseRequest.Descendants("FRAME");

            foreach (XElement _element in TagFRAME)
            {
                if (_element.Name.LocalName == "FRAME")
                {
                    _element.Element("UPC").Value = modelCheckOrder.FRAME_UPC;
                    _element.Element("DBL").Value = modelCheckOrder.FRAME_DBL;
                }
            }


            ////////////////////////////////////
            //
            // ...now the XML document
            //
            ////////////////////////////////////

            XmlDocument soapEnvelopeXml = new XmlDocument();

            soapEnvelopeXml.LoadXml(baseRequest.ToString());


            //
            // Logging
            //
            //if (_iLoggingLevel > (int)LoggingLevelEnums.None)
            //{
            //    ExceptionLoggingService.Instance.WriteRXOWSLog("HTTPClient.InvokeRXOCheckOrder", "rxoCheckOrder Request", soapEnvelopeXml.InnerXml.ToString());
            //}


            ////////////////////////////////////
            //
            //
            //
            ////////////////////////////////////

            using (Stream stream = request.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }


            ////////////////////////////////////
            //
            //
            //
            ////////////////////////////////////

            try
            {
                WebResponse webResponse = request.GetResponse();

                using (Stream webStream = webResponse.GetResponseStream())
                {
                    if (webStream != null)
                    {
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {
                            soapResult = responseReader.ReadToEnd();
                            Console.WriteLine(soapResult);

                            //
                            // Logging
                            //
                            //if (_iLoggingLevel > (int)LoggingLevelEnums.None)
                            //{
                            //    ExceptionLoggingService.Instance.WriteRXOWSLog("HTTPClient.InvokeRXOCheckOrder", "rxoCheckOrder Response", soapResult);
                            //}

                            //
                            // Now parse the response
                            //
                            string     strResponseCode = null;
                            XDocument  doc             = XDocument.Parse(soapResult);
                            XNamespace ns = "http://rxo.webservices.luxottica.it/";

                            iReturnFromResponse = 502;

                            IEnumerable <XElement> responses = doc.Descendants("LMS_MAKEABILITY_SUCCESS_RESULT");
                            if (responses.Count() > 0)
                            {
                                foreach (XElement _element in responses)
                                {
                                    strResponseCode = (string)_element.Element("FRAME_IN_STOCK");
                                }

                                if (strResponseCode != null)
                                {
                                    if (strResponseCode == "Y")
                                    {
                                        responseCheckOrder.ErrorCode        = 0;
                                        responseCheckOrder.ErrorDescription = "Y";
                                        iReturnFromResponse = 0;
                                    }
                                    else
                                    {
                                        responseCheckOrder.ErrorCode        = 0;
                                        responseCheckOrder.ErrorDescription = "N";
                                        iReturnFromResponse = 0;
                                    }
                                }
                            }

                            IEnumerable <XElement> responses2 = doc.Descendants("LMS_MAKEABILITY_FAILURE_RESULT_ENTRY");
                            if (responses2.Count() > 0)
                            {
                                foreach (XElement _element in responses2)
                                {
                                    if (_element.Name.LocalName == "LMS_MAKEABILITY_FAILURE_RESULT_ENTRY")
                                    {
                                        strResponseCode = (string)_element.Element("EYENET_ERROR_CODE");
                                        responseCheckOrder.ErrorCode        = Convert.ToInt32(strResponseCode);
                                        responseCheckOrder.ErrorDescription = (string)_element.Element("EYENET_ERROR_MESSAGE");
                                    }
                                }
                                iReturnFromResponse = 502;
                            }
                        }
                    }
                }
            }
            catch (WebException webex)
            {
                //var resp = new StreamReader(webex.Response.GetResponseStream()).ReadToEnd();

                if (webex.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = webex.Response as HttpWebResponse;
                    if (response != null)
                    {
                        Console.WriteLine("HTTP Status Code: " + (int)response.StatusCode);
                        iReturnFromResponse = (int)response.StatusCode;
                    }
                    else
                    {
                        // no http status code available
                    }
                }
                else if (webex.Status == WebExceptionStatus.Timeout)
                {
                    iReturnFromResponse = (int)HttpStatusCode.RequestTimeout;
                }
                else
                {
                    // no http status code available
                }
            }
            catch (Exception ex)
            {
                iReturnFromResponse = 502;
            }

            responseCheckOrder.ErrorCode        = iReturnFromResponse;
            responseCheckOrder.ErrorDescription = DecodeResponseCodes(iReturnFromResponse);

            // Override specifics
            if (responseCheckOrder.ErrorCode != -999)
            {
                responseCheckOrder.ErrorCode        = responseCheckOrder.ErrorCode;
                responseCheckOrder.ErrorDescription = responseCheckOrder.ErrorDescription;
            }

            // Auditing

            RxoWsAuditing recordAudit = new RxoWsAuditing()
            {
                DoorNumber       = modelCheckOrder.ACCOUNT,
                EventName        = "CheckOrder",
                EventDescription = "Request to Luxottica Rxo CheckOrder WebService",
                EventDate        = DateTime.Now,
                EventStatus      = responseCheckOrder.ErrorCode.ToString(),
                EventRequest     = stringRequest,
                EventResponse    = soapResult
            };

            rxoRepository.AddEntity(recordAudit);

            if (!rxoRepository.SaveAll())
            {
                // ...some logging...
            }



            return(responseCheckOrder);
        }
Пример #2
0
        public IActionResult Post([FromBody] RxoCheckOrderViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newCheckOrderRequest = new RxoCheckOrderRequest()
                    {
                        arg0 = model.OrderGroupID,

                        //ORIGIN_NAME =

                        ACCOUNT            = model.UserName,
                        PATIENT_FIRST_NAME = model.OrderGroupID,
                        PATIENT_LAST_NAME  = model.DisplayID,
                        LENS_SALES_ARTICLE = model.LensCode,

                        //
                        // LENS R
                        //

                        LENS_R_TYPE       = model.RightEye.Lens_Type,
                        LENS_R_SPHERE     = model.RightEye.sphere,
                        LENS_R_CYLINDER   = model.RightEye.cylinder,
                        LENS_R_AXIS       = model.RightEye.axis,
                        LENS_R_DISTANCE   = model.RightEye.DI,
                        LENS_R_ADD        = model.RightEye.add,
                        LENS_R_SEG_HEIGHT = model.RightEye.ProgHeight,
                        LENS_R_OC_HEIGHT  = (model.RightEye.MonoHeight == null ? "" : model.RightEye.MonoHeight),

                        //
                        // LENS L
                        //

                        LENS_L_TYPE       = model.LeftEye.Lens_Type,
                        LENS_L_SPHERE     = model.LeftEye.sphere,
                        LENS_L_CYLINDER   = model.LeftEye.cylinder,
                        LENS_L_AXIS       = model.LeftEye.axis,
                        LENS_L_DISTANCE   = model.LeftEye.DI,
                        LENS_L_ADD        = model.LeftEye.add,
                        LENS_L_SEG_HEIGHT = model.LeftEye.ProgHeight,
                        LENS_L_OC_HEIGHT  = (model.LeftEye.MonoHeight == null ? "" : model.LeftEye.MonoHeight),

                        //
                        // FRAME
                        //
                        FRAME_UPC = model.FrameID,
                        FRAME_DBL = ""
                    };

                    // Invoke the Service
                    var RxoWsResponse = luxotticaRxoSvc.CallCheckOrder(newCheckOrderRequest);

                    return(Ok(RxoWsResponse));
                }
                else
                {
                    // Show the errors
                    return(BadRequest("CheckOrder invalid model"));
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Luxottica CheckOrder Error : {ex}");
                return(BadRequest("CheckOrder Error"));
            }
        }