public IActionResult Calculate(CalculateRequest request) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } // Loosely Typed View Data ViewData["StartTime"] = DateTime.Now; // Strongly Typed Model var model = _mathService.Calculate(request); // Loosely Typed View Bag ViewBag.EndTime = DateTime.Now; // Loosely Typed Temp Data (Read Once) var lastRequest = $"The last request was to {request.Type} {request.FirstNumber} and {request.SecondNumber}"; TempData["LastRequest"] = lastRequest; // Setting in the session to be reused _httpContext.HttpContext.Session.SetString("lastRequest", lastRequest); // Setting in the cookie (always in the response) _httpContext.HttpContext.Response.Cookies.Append("lastRequest", lastRequest); return(View(model)); }
public IActionResult Calculate(CalculateRequest request) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var model = _mathService.Calculate(request); return(View(model)); }
public IActionResult Calculate([FromQuery] string query) { // https://localhost:44397/api/Math/calculate?query=11%2B61 example if (string.IsNullOrWhiteSpace(query)) { return(BadRequest()); } try { return(new ObjectResult(_mathService.Calculate(query))); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }