public void Add(int testId, int studentId, QuesGiveTestViewModel model) { var question = _questionRepo.GetById(model.Id); var response = new Response(); switch (model.Answer) { case "A": response.Answer = question.OptionA; break; case "B": response.Answer = question.OptionB; break; case "C": response.Answer = question.OptionC; break; case "D": response.Answer = question.OptionD; break; default: response.Answer = ""; break; } response.DataTime = DateTime.Now; response.QuestionId = model.Id; response.TestId = testId; response.StudentId = studentId; _responseRepo.Add(response); }
public async Task <IActionResult> QuesForTest(int id, QuesGiveTestViewModel model) { try { var email = await GetEmail(); var student = _studentService.GetStudentByEmail(email); _responseService.Add(model.TestId, student.Id, model); ViewBag.Id = model.TestId; var count = _testQuesService.GetTestQuesByTestId(model.TestId).Count(); ViewBag.Count = count; if (count <= model.No) { return(RedirectToAction("TestCompleted")); } var question = _questionService.GetQuestionForGivingTest(model.TestId, model.No + 1); ViewBag.No = ++model.No; return(View(question)); } catch (Exception e) { ViewBag.Error = "Something went wrong"; return(View("TestCompleted")); } }
/// <summary> /// get question for giving test /// </summary> /// <param name="testId"></param> /// <param name="no"></param> /// <returns>question</returns> public QuesGiveTestViewModel GetQuestionForGivingTest(int testId, int no) { no = --no; //get current question for student to attempt var testQues = _testQuesRepo.GetByTestId(testId).Skip(no).Take(1).First(); var question = _questionRepo.GetById(testQues.QuestionId); var quesForTest = new QuesGiveTestViewModel() { Id = question.Id, OptionA = question.OptionA, OptionB = question.OptionB, OptionC = question.OptionC, OptionD = question.OptionD, QuesSting = question.QuesString, Time = question.Time, Marks = question.Marks, TestId = testId }; return(quesForTest); }