Exemplo n.º 1
0
        }        //Sub

        public static string Mult(List <string> data)
        {
            string      responseFinal  = null;
            string      responseServer = "";
            MultFactors objMulFactors  = new MultFactors(data);

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

            MultProduct objMultProduct = new MultProduct(JsonConvert.DeserializeObject <MultProduct>(responseServer).Product);

            if (objMultProduct.Product == null)
            {
                Error ErrorMult = JsonConvert.DeserializeObject <Error>(responseServer);
                responseFinal = ErrorMult.ErrorMessage;
            }
            else
            {
                responseFinal = objMultProduct.Product;
            }
            return(responseFinal);
        }        //Mult
Exemplo n.º 2
0
        [HttpPost] //CLOSED
        public string Mult(MultFactors NumbersForMult)
        {
            try {
                double result             = 1;
                string stringOperationLog = "";
                string idApp = GetIdTracking(Request.Headers["X-Evi-Tracking-Id"]);

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

                double numD;
                foreach (string num in NumbersForMult.Factors)
                {
                    if (!double.TryParse(num, out numD))
                    {
                        Error objectFinalError = new Error();
                        objectFinalError.Error400();
                        logger.Trace("ERROR MULT -> ID : " + idApp + " MENSAJE : OPERADORES INVALIDOS.");
                        return(JsonConvert.SerializeObject(objectFinalError));
                    }
                    if (num.Contains(","))
                    {
                        string[] arr    = num.Split(',');
                        string   numAux = string.Join(".", arr);
                        result += Convert.ToDouble(numAux);
                    }
                    else
                    {
                        result *= Convert.ToDouble(num);
                    }
                }
                stringOperationLog = string.Join(" * ", NumbersForMult.Factors) + " = " + result;
                if (idApp != "NULL")
                {
                    string  calculation   = string.Join(" * ", NumbersForMult.Factors);
                    Query   Operation     = new Query("Mult", calculation + " = " + result);
                    string  jsonOperation = JsonConvert.SerializeObject(Operation);
                    Journal journal       = new Journal(Request.Headers["X-Evi-Tracking-Id"]);
                    journal.SaveJournal(jsonOperation);
                    stringOperationLog = "MULT -> ID : " + idApp + "  OPERATION :" + stringOperationLog;
                }
                else
                {
                    stringOperationLog = "MULT -> ID : " + idApp + "  OPERATION :" + stringOperationLog;
                }
                logger.Trace(stringOperationLog);

                MultProduct responseProduct = new MultProduct();
                responseProduct.Product = Convert.ToString(result);

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