public IActionResult Index(IndexViewModel model) { if (this.ModelState.IsValid) { //cache string key = string.Format("TestId {0}", model.TestId); this.cache.Remove(key); model.SubmitedOn = DateTime.Now; var testDuration = model.SubmitedOn.Subtract(model.StartedOn); var testRequiredTimeSeconds = tests.GetTestDurationSeconds(model.TestId); if (testRequiredTimeSeconds < testDuration.TotalSeconds - 5) { TempData["Error-Message"] = "Test submition failed, please do not turn off JS!"; return(Json(Url.Action("All", "Dashboard"))); } var currentTestEntity = resultService.GetStartedTest(model.UserId, model.TestId); currentTestEntity.SubmittedOn = model.SubmitedOn; currentTestEntity.ExecutionTime = testDuration; int correctAnswers = this.CalculateCorrectAnswers(model.Questions); int totalQuestions = model.Questions.Count(); currentTestEntity.Points = this.resultService.CalculateTestPoints(correctAnswers, totalQuestions); currentTestEntity.IsPassed = (currentTestEntity.Points > 80) ? true : false; resultService.Submit(currentTestEntity); //cache this.cache.Remove("TestResults"); TempData["Success-Message"] = "Test submited!"; } else { TempData["Error-Message"] = "Test submition failed!"; } return(Json(Url.Action("All", "Dashboard"))); }