Ejemplo n.º 1
0
        public ActionResult XMLGetCustomers(string responseFormat)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            GlobalVars.ResultCustomers resultCustomers = new GlobalVars.ResultCustomers();
            try
            {
                logger.Info("GetCustomers API Request.");
                resultCustomers = SQLFunctionsCustomers.GetCustomers();
                switch (resultCustomers.ReturnCode)
                {
                case 0:
                    logger.Info("GetCustomers API Request was executed Successfully.");
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    break;

                case -2:
                    Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    logger.Fatal("GetCustomers API Request ends with a Fatal Error.");
                    logger.Debug("Returned value:" + JsonConvert.SerializeObject(resultCustomers, Formatting.Indented));
                    Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                    break;
                }
            }
            catch (Exception e)
            {
                logger.Fatal("GetCustomers API Request ends with a Fatal Error.");
                resultCustomers.ReturnCode = -2;
                resultCustomers.Message    = e.Message;
                var baseException = e.GetBaseException();
                resultCustomers.Exception = baseException.ToString();
                logger.Fatal("Returned value:" + JsonConvert.SerializeObject(resultCustomers, Formatting.Indented));
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }
            Response.ContentType = "application/xml";
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            elapsedMs = elapsedMs / 1000;
            resultCustomers.ElapsedTime = elapsedMs.ToString();
            logger.Debug("Returned value:" + JsonConvert.SerializeObject(resultCustomers, Formatting.Indented));
            //var messaje = JsonConvert.SerializeObject(resultCustomers, Formatting.Indented);
            resultCustomers.HttpStatusCode = Response.StatusCode.ToString();
            var messaje = XMLTools.GetXMLFromObject(resultCustomers);

            logger.Info("Leaving GetCustomers API.");
            return(Content(messaje));
        }