public SubtractionResult Sub([FromBody] SubtractionRequest subRequest)
        {
            var    headers     = this.Request.Headers.ToList();
            string trackingSub = headers[headers.Count - 1].Value.First().ToString();

            return(CalculatorBusiness.Sub(subRequest, trackingSub));
        }
        public override Task <OperationResponse> Calculate(SubtractionRequest request, ServerCallContext context)
        {
            var result = request.FirstOperand - request.SecondOperand;

            System.Console.WriteLine("Subtraction request -> {0} - {1} = {2}", request.FirstOperand, request.SecondOperand, request.FirstOperand - request.SecondOperand);

            return(Task.FromResult(new OperationResponse()
            {
                Result = result
            }));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Group the subtraction operations.
        /// </summary>
        static public void SubtractionMethod()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("RESTA ");
            Console.ForegroundColor = ConsoleColor.White;

            int minuend     = int.Parse(ValidarNumero("Ingrese el minuendo:"));
            int subtracting = int.Parse(ValidarNumero("Ingrese sustraendo:"));

            string             logSub     = ValidarNumeroEspacio("\nIngrese el identificador del Log OPCIONAL:");
            SubtractionRequest subRequest = new SubtractionRequest();

            subRequest.Minuend    = minuend;
            subRequest.Subtrahend = subtracting;
            ManagementCalculator.Substraction(subRequest, logSub);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Implementation of subtraction method.
        /// </summary>
        /// <param name="subtractionRequest"></param>
        /// <param name="logSub"></param>
        /// <returns></returns>
        public static SubtractionResult Sub(SubtractionRequest subtractionRequest, string logSub)
        {
            try
            {
                SubtractionResult subtractionResult = new SubtractionResult();

                subtractionResult.Difference = subtractionRequest.Minuend - subtractionRequest.Subtrahend;
                string calculation = subtractionRequest.Minuend.ToString() + "-" + subtractionRequest.Subtrahend.ToString();

                if (int.Parse(logSub) != 0)
                {
                    SaveLog(int.Parse(logSub), "Resta ", calculation, subtractionResult.Difference);
                }

                return(subtractionResult);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Method that connects to the Web API service to perform the substraction operation.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="logSub"></param>
        public static void Substraction(SubtractionRequest values, string logSub)
        {
            try
            {
                var clientRest  = new RestClient(urlWebAPI);
                var requestRest = new RestRequest("Sub", Method.POST);

                if (logSub == "")
                {
                    logSub = "0";
                }
                requestRest.AddHeader("x-evi-tracking-id", logSub);

                requestRest.AddParameter("application/json", new JavaScriptSerializer().Serialize(values), ParameterType.RequestBody);
                IRestResponse responseRest = clientRest.Execute(requestRest);
                Console.WriteLine();

                if (responseRest.StatusCode == HttpStatusCode.OK)
                {
                    SubtractionResult resultSubs = (new JavaScriptSerializer()).Deserialize <SubtractionResult>(responseRest.Content);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("\n\nRESULTADO, DIFERENCIA: " + resultSubs.Difference + ". " + (logSub != "0" ? " La operacion fue registrada en el log. " : ""));
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error al realizar la operación: " + responseRest.ErrorMessage);
                }

                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Operación finalizada.");
                Console.WriteLine();
            }
            catch (Exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\n\nError al conectarse con el servicio que realiza la operacion de resta. ");
                throw;
            }
        }
Ejemplo n.º 6
0
 public static SubtractionResult Sub(SubtractionRequest subtractionRequest, string tracking_ID)
 {
     return(CalculatorDataAccess.Sub(subtractionRequest, tracking_ID));
 }
Ejemplo n.º 7
0
        public IActionResult Post([FromBody] SubtractionRequest request)
        {
            double result = SubtractionHelper.Calculate(request.Arg1, request.Arg2);

            return(new JsonResult(result));
        }