Beispiel #1
0
        public ActionResult GetReports()
        {
            // The following section is just a test for the reporting
            //GlobalVars.ResultGeneric rg = new GlobalVars.ResultGeneric();
            // rg = SQLFunctionsReports.OverallBatchStatusReport(reportID);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            GlobalVars.ResultReports resultReport = new GlobalVars.ResultReports();
            try
            {
                logger.Info("GetReports API Request.");

                resultReport = SQLFunctionsReports.GetReports();
                switch (resultReport.ReturnCode)
                {
                case 0:
                    logger.Info("GetReports API Request was executed Successfully.");
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    break;

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

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

            logger.Info("Leaving GetReports API.");
            //return Json(messaje);
            return(Content(messaje));
        }
Beispiel #2
0
        public ActionResult GetReportsByCustomerName(string customerName)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            GlobalVars.ResultReports resultReports = new GlobalVars.ResultReports();
            try
            {
                logger.Info("GetReportsByCustomerName API Request.");

                if (string.IsNullOrEmpty(customerName))
                {
                    Response.StatusCode      = (int)HttpStatusCode.BadRequest;
                    resultReports.ReturnCode = -1;
                    resultReports.Message    = "Missing argument customerName";
                    logger.Warn("GetReportsByCustomerName API Request ends with an Error.");
                    logger.Warn(resultReports.Message);
                }
                else
                {
                    resultReports = SQLFunctionsReports.GetReportsByCustomerName(customerName);
                    switch (resultReports.ReturnCode)
                    {
                    case 0:
                        logger.Info("GetReportsByCustomerName API Request was executed Successfully.");
                        Response.StatusCode = (int)HttpStatusCode.OK;
                        break;

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

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

            logger.Info("Leaving GetReportsByCustomerName API.");
            //return Json(messaje);
            return(Content(messaje));
        }