public IActionResult Dountil(string what, [FromBody] Dountil dountil) { if (what == "sum") { if (dountil.Number == null) { return(Json(new { error = "Please provide a number!" })); } else { return(Json(new { result = dountil.Sum(dountil.Number) })); } } else if (what == "factor") { if (dountil.Number == null) { return(Json(new { error = "Please provide a number!" })); } else { return(Json(new { result = dountil.Factor(dountil.Number) })); } } return(Json(new { error = "Please provide what to do with the numbers!" })); }
public ActionResult <Dountil> Factor(Dountil dountil) { if (dountil.Until == 0) { return new Dountil { Error = "Please provide a number!" } } ; return(new Dountil { Result = frontendServices.Factor(dountil.Until) }); }
public IActionResult Dountil(string what, [FromBody] Dountil until) { var log = new Log { CreatedAt = DateTime.Now, EndPoint = $"/dountil/{what}", Data = $"what={what}&until={until.Until}" }; logCont.logs.Add(log); logCont.SaveChanges(); if (what == "sum") { int result = 0; for (int i = 0; i < until.Until; i++) { result += i; } return(new JsonResult(new { result })); } else if (what == "factor") { int result = 1; for (int i = 1; i <= until.Until; i++) { result *= i; } return(new JsonResult(new { result })); } else { return(new JsonResult(new { error = "Please provide a number." })); } }