public IActionResult CreateExam(ExamQuestionModel model) { if (ModelState.IsValid) { Exam exam = new Exam(); exam.Content = model.Exam.Content; exam.CreatedDate = DateTime.Now; exam.Title = model.Exam.Title; exam.Questions = model.Questions; _examService.Save(exam); ExamType examType = new ExamType(); if (examType.Id == 0) { examType.Id = 1; } else { examType.Id = examType.Id + 1; } examType.Content = model.Exam.Content; examType.CreatedDate = DateTime.Now; examType.Title = model.Exam.Title; examType.Questions = model.Questions; _examTypeService.Save(examType); } return(RedirectToAction("GetExamList")); }
public ResponseModel <List <ExamQuestionModel> > ListExamQuestionsByExam(int TestId) { ResponseModel <List <ExamQuestionModel> > result = new ResponseModel <List <ExamQuestionModel> > { Data = new List <ExamQuestionModel>() }; try { var lst = _context.ExamQuestions.Where(e => e.ExamId == TestId && e.IsActive == true).ToList(); foreach (var item in lst) { ExamQuestionModel model = new ExamQuestionModel(); model.TestId = item.ExamId; model.QuestionId = item.QuestionId; model.Question = item.Question; model.CreatedOn = item.CreatedOn; model.IsActive = true; result.Data.Add(model); } result.status = true; result.message = "success"; } catch (Exception ex) { result.message = ex.Message; } return(result); }