Beispiel #1
0
        }        //Add

        public static string Sub(List <string> data)
        {
            string       responseFinal   = null;
            string       responseServer  = "";
            SubOperators objSubOperators = new SubOperators(data);

            responseServer = MakeRequest(JsonConvert.SerializeObject(objSubOperators));

            SubDiference objSubDiference = new SubDiference(JsonConvert.DeserializeObject <SubDiference>(responseServer).Diference);

            if (objSubDiference.Diference == null)
            {
                Error ErrorSub = JsonConvert.DeserializeObject <Error>(responseServer);
                responseFinal = ErrorSub.ErrorMessage;
            }
            else
            {
                responseFinal = objSubDiference.Diference;
            }
            return(responseFinal);
        }        //Sub
Beispiel #2
0
        [HttpPost] //CLOSED
        public string Sub(SubOperators NumbersForSubtract)
        {
            try {
                double result             = 0;
                string stringOperationLog = "";



                string idApp = GetIdTracking(Request.Headers["X-Evi-Tracking-Id"]);

                if (NumbersForSubtract.Operators == null || NumbersForSubtract == null)
                {
                    Error objectFinalError = new Error();
                    objectFinalError.Error400();
                    logger.Trace("ERROR SUB -> ID : " + idApp + " MENSAJE : OPERADORES NULOS.");
                    return(JsonConvert.SerializeObject(objectFinalError));
                }



                double        numD;
                List <double> list = new List <double>();
                foreach (string num in NumbersForSubtract.Operators)
                {
                    if (!double.TryParse(num, out numD))
                    {
                        Error objectFinalError = new Error();
                        objectFinalError.Error400();
                        logger.Trace("ERROR SUB -> ID : " + idApp + " MENSAJE : OPERADORES INVALIDOS.");
                        return(JsonConvert.SerializeObject(objectFinalError));
                    }

                    if (num.Contains(","))
                    {
                        string[] arrSub = num.Split(',');
                        string   numAux = string.Join(".", arrSub);
                        list.Add(Convert.ToDouble(numAux));
                    }
                    else
                    {
                        list.Add(Convert.ToDouble(num));
                    }
                }
                result = list[0];
                list.RemoveRange(0, 1);

                foreach (double num in list)
                {
                    result = result - num;
                }
                stringOperationLog = string.Join(" - ", NumbersForSubtract.Operators) + " = " + result;
                result             = Math.Round(result, 2);
                if (idApp != "NULL")
                {
                    string  calculation   = string.Join(" - ", NumbersForSubtract.Operators);
                    Query   Operation     = new Query("Sub ", calculation + " = " + result);
                    string  jsonOperation = JsonConvert.SerializeObject(Operation);
                    Journal journal       = new Journal(Request.Headers["X-Evi-Tracking-Id"]);
                    journal.SaveJournal(jsonOperation);
                    stringOperationLog = "SUB  -> ID : " + idApp + "  OPERATION :" + stringOperationLog;
                }
                else
                {
                    stringOperationLog = "SUB  -> ID : " + idApp + "  OPERATION :" + stringOperationLog;
                }

                logger.Trace(stringOperationLog);

                SubDiference responseDiference = new SubDiference();
                responseDiference.Diference = Convert.ToString(result);

                return(JsonConvert.SerializeObject(responseDiference));
            }
            catch (Exception ex)
            {
                Error objectFinalError = new Error();
                objectFinalError.Error500(ex.StackTrace);
                return(JsonConvert.SerializeObject(objectFinalError));
            }
        }          //Sub