public IActionResult CheckFrame([FromForm] RxoCheckFrameViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newCheckFrameRequest = new RxoCheckFrameRequest()
                    {
                        Kunnr = model.DoorNr,
                        Upc   = model.FrameUpc
                    };

                    // Invoke the Service
                    var RxoWsResponse = luxotticaRxoSvc.CallCheckFrame(newCheckFrameRequest);

                    ViewBag.UserMessage = RxoWsResponse;
                    ModelState.Clear();
                }
                else
                {
                    // Show the errors
                    ViewBag.UserMessage = "Error";
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Luxottica CheckFrame Error : {ex}");
            }
            return(View());
        }
Esempio n. 2
0
        public IActionResult Post([FromBody] RxoCheckFrameViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newCheckFrameRequest = new RxoCheckFrameRequest()
                    {
                        Kunnr = model.DoorNr,
                        Upc   = model.FrameUpc
                    };

                    // Invoke the Service
                    var RxoWsResponse = luxotticaRxoSvc.CallCheckFrame(newCheckFrameRequest);

                    return(Ok(RxoWsResponse));
                }
                else
                {
                    // Show the errors
                    return(BadRequest("CheckFrame invalid model"));
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Luxottica CheckFrame Error : {ex}");
                return(BadRequest("CheckFrame Error"));
            }
        }
        public RxoBaseResponseEntity CallCheckFrame(RxoCheckFrameRequest modelCheckFrame)
        {
            int    iReturnFromResponse = 0;
            string soapResult          = "";

            RxoBaseResponseEntity responseCheckFrame = new RxoBaseResponseEntity();

            HttpWebRequest request = CreateWebRequest(configRxoWs);

            XmlDocument soapEnvelopeXml = new XmlDocument();

            string stringRequest = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:rxo=""http://rxo.webservices.luxottica.it/"">
                                        <soapenv:Header/>
                                        <soapenv:Body>
                                          <rxo:rxoCheckFrame>
                                            <arg0>{0}</arg0>
                                            <arg1>{1}</arg1>
                                          </rxo:rxoCheckFrame>
                                        </soapenv:Body>
                                      </soapenv:Envelope>";

            stringRequest = String.Format(stringRequest, modelCheckFrame.Kunnr, modelCheckFrame.Upc);

            soapEnvelopeXml.LoadXml(stringRequest);

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

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

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                        Console.WriteLine(soapResult);

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

                        //
                        // Now parse the response
                        //
                        string                 strResponseCode = null;
                        XDocument              doc             = XDocument.Parse(soapResult);
                        XNamespace             ns        = "http://rxo.webservices.luxottica.it/";
                        IEnumerable <XElement> responses = doc.Descendants(ns + "rxoCheckFrameResponse");
                        foreach (XElement _element in responses)
                        {
                            strResponseCode = (string)_element.Element("return");
                        }

                        if (strResponseCode != null)
                        {
                            iReturnFromResponse = 500;
                            Int32.TryParse(strResponseCode, out iReturnFromResponse);
                        }
                        else
                        {
                            iReturnFromResponse = 501;
                        }
                    }
                }
            }
            catch (WebException webex)
            {
                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
                {
                    // no http status code available
                }
            }
            catch (Exception ex)
            {
                iReturnFromResponse = 501;
            }

            responseCheckFrame.WebService       = @"https://certi-my.luxottica.com:443/Stores-WS/RXOServiceImplService";
            responseCheckFrame.ErrorCode        = iReturnFromResponse;
            responseCheckFrame.ErrorDescription = DecodeResponseCodes(iReturnFromResponse);

            // Auditing

            RxoWsAuditing recordAudit = new RxoWsAuditing()
            {
                DoorNumber       = modelCheckFrame.Kunnr,
                EventName        = "CheckFrame",
                EventDescription = "Request to Luxottica Rxo WebService",
                EventDate        = DateTime.Now,
                EventStatus      = iReturnFromResponse.ToString(),
                EventRequest     = stringRequest,
                EventResponse    = soapResult
            };

            rxoRepository.AddEntity(recordAudit);

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

            return(responseCheckFrame);
        }