public IActionResult mult([FromBody] CalcMult par) { var headers = Request.Headers; string track = headers.Where(x => x.Key == "X-Evi-Tracking-Id").FirstOrDefault().Value; if (par.Factors.Count < 2) { return(BadRequest(new BadCalc { ErrorCode = "InternalError", ErrorStatus = 400, ErrorMessage = "Unable to process request: it's necessary at least 2 numbers for multiply." })); } string msg = "(" + par.Factors[0].ToString() + " * "; double total = par.Factors[0]; for (int i = 1; i < par.Factors.Count; i++) { total *= par.Factors[i]; msg += par.Factors[i] + (i < (par.Factors.Count - 1) ? " * " : ""); } msg += ") = " + total.ToString("0.#####"); if (!string.IsNullOrEmpty(track)) { _trk.Operations.Add(new Operations { Id = track, Operation = "Mult", Calculation = msg, Date = DateTime.Now }); } return(Ok(new { Product = total })); }
/// <summary> /// Multiply two or more operands and retrieve the result /// </summary> /// <param name="id">Id Tracking</param> /// <returns></returns> public static string Mult(string id) { CalcMult par = new CalcMult(); par.Factors = GetNumbers("mult", 0); if (par.Factors.Count >= 2) { return(CallRestApi <CalcMult>(par, "mult", id)); } else { return(BadCalculate()); } }