//End passing test, count result. public ActionResult Result(string [] questionId, string[] answerIdQuestionId, Guid idTest, DateTime timeStart) { DateTime timeEnd = DateTime.Now; Guid studResultId = testResultService.AddStudResultReturnId(User.Identity.GetUserId(), idTest, timeStart, timeEnd); Logger.Log.Info("User " + User.Identity.GetUserId() + "end passing the test"); //for (int i = 0; i < questionId.Length; i++) //{ // bool giveAnsw = false; // int count = 0; // if (answerIdQuestionId != null) // { // for (int j = 0; j < answerIdQuestionId.Length; j++) // { // string[] quesAnsw = answerIdQuestionId[j].Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); // if ((new Guid(questionId[i])) == (new Guid(quesAnsw[0]))) // { // testResultService.AddAnswerGivenByStud((new Guid(quesAnsw[0])), (new Guid(quesAnsw[1])), studResultId); // giveAnsw = true; // } // else // { // count++; // } // } // if (count == answerIdQuestionId.Length && giveAnsw == false) // { // testResultService.AddAnswerGivenByStud((new Guid(questionId[i])), (Guid.Empty), studResultId); // break; // } // Logger.Log.Info("User " + User.Identity.GetUserId() + "didnt give any answer"); // } // else // { // testResultService.AddAnswerGivenByStud((new Guid(questionId[i])), (Guid.Empty), studResultId); // } //} for (int i = 0; i < questionId.Length; i++) { if (answerIdQuestionId != null) { bool find = false; for (int j = 0; j < answerIdQuestionId.Length; j++) { string[] quesAnsw = answerIdQuestionId[j].Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries); if ((new Guid(questionId[i])) == (new Guid(quesAnsw[0]))) { testResultService.AddAnswerGivenByStud((new Guid(quesAnsw[0])), (new Guid(quesAnsw[1])), studResultId); find = true; } } if (find == false) { testResultService.AddAnswerGivenByStud((new Guid(questionId[i])), (Guid.Empty), studResultId); } } else { testResultService.AddAnswerGivenByStud((new Guid(questionId[i])), (Guid.Empty), studResultId); } } double mark = testResultService.CountMarkForTest(idTest, studResultId); testResultService.UpdateStudResult(mark, studResultId); Logger.Log.Info("User " + User.Identity.GetUserId() + "markr " + mark); ViewBag.mark = mark; ViewBag.timeStart = timeStart; ViewBag.timeEnd = timeEnd; return(View()); }