public ActionResult Index(QuestionFilterModel searchModel) { var listCategory = questionCategorySevice.GetAllQuestionCategoriesActive(); var listLevels = questionService.GetAlLevels(); ViewData["Category"] = listCategory; ViewData["Level"] = listLevels; var listQuestionDtos = questionService.GetAllQuestionDtos(searchModel); ViewBag.listQuestionDtos = listQuestionDtos; return(View()); }
/// <summary> /// The ExamPaperTemplateFile /// </summary> public void ExamPaperTemplateFile() { ExcelPackage pck = new ExcelPackage(); ExcelWorksheet ws = pck.Workbook.Worksheets.Add("ExamPaper"); ws.Cells["A1"].Style.Font.Bold = true; ws.Cells["A1"].Value = "Exam Paper Infomation"; ws.Cells["A3"].Style.Font.Bold = true; ws.Cells["A3"].Value = "Title"; ws.Cells["B3"].Value = "Exam paper title"; ws.Cells["A4"].Style.Font.Bold = true; ws.Cells["A4"].Value = "Time"; ws.Cells["B4"].Value = "120"; ws.Cells["A5"].Style.Font.Bold = true; ws.Cells["A5"].Value = "Status"; var status = ws.DataValidations.AddListValidation("B5"); status.Formula.Values.Add("Public"); status.Formula.Values.Add("Draff"); ws.Cells["A6"].Style.Font.Bold = true; ws.Cells["A6"].Value = "Is Active"; ws.Cells["B6"].Value = "TRUE"; ws.Cells["A8"].Style.Font.Bold = true; ws.Cells["A8"].Value = "Question Infomation"; ws.Cells["D8"].Style.Font.Bold = true; ws.Cells["D8"].Value = "Answer Infomation"; ws.Cells["A10"].Style.Font.Bold = true; ws.Cells["A10"].Value = "Question Content"; ws.Cells["B10"].Style.Font.Bold = true; ws.Cells["B10"].Value = "Level"; ws.Cells["C10"].Style.Font.Bold = true; ws.Cells["C10"].Value = "Category"; ws.Cells["D10"].Style.Font.Bold = true; ws.Cells["D10"].Value = "Answer1"; ws.Cells["E10"].Style.Font.Bold = true; ws.Cells["E10"].Value = "IsCorrect Answer1"; ws.Cells["F10"].Style.Font.Bold = true; ws.Cells["F10"].Value = "Answer2"; ws.Cells["G10"].Style.Font.Bold = true; ws.Cells["G10"].Value = "IsCorrect Answer2"; ws.Cells["H10"].Style.Font.Bold = true; ws.Cells["H10"].Value = "Answer3"; ws.Cells["I10"].Style.Font.Bold = true; ws.Cells["I10"].Value = "IsCorrect Answer3"; ws.Cells["J10"].Style.Font.Bold = true; ws.Cells["J10"].Value = "Answer4"; ws.Cells["K10"].Style.Font.Bold = true; ws.Cells["K10"].Value = "IsCorrect Answer4"; ws.Cells["L10"].Style.Font.Bold = true; ws.Cells["L10"].Value = "Answer5"; ws.Cells["M10"].Style.Font.Bold = true; ws.Cells["M10"].Value = "IsCorrect Answer5"; ws.Cells["A11"].Value = "Which of the following is not true about the MAX and MIN functions?"; var level = ws.DataValidations.AddListValidation("B11"); level.Formula.Values.Add("Easy"); level.Formula.Values.Add("Normal"); level.Formula.Values.Add("Hard"); var category = ws.DataValidations.AddListValidation("C11"); ws.Cells["D11"].Value = "Both can be used for any data type"; ws.Cells["E11"].Value = "FALSE"; ws.Cells["F11"].Value = "MAX return maximun value"; ws.Cells["G11"].Value = "FALSE"; ws.Cells["H11"].Value = "MIN return minium value"; ws.Cells["I11"].Value = "FALSE"; ws.Cells["J11"].Value = "All are true"; ws.Cells["K11"].Value = "TRUE"; ExcelWorksheet noteSheet = pck.Workbook.Worksheets.Add("Note"); noteSheet.Cells["A1"].Style.Font.Bold = true; noteSheet.Cells["A1"].Value = "(*) Note"; noteSheet.Cells["A2"].Value = @"To import exam paper correctly, ""Satus"", ""Level"", ""Category"" must select from dropdown list"; noteSheet.Cells["A3"].Value = @"For each question have maximum 5 answer, if there is no content leave It blank"; noteSheet.Cells["A:AZ"].AutoFitColumns(); var listQuestionCategory = questionCategorySevice.GetAllQuestionCategoriesActive(); foreach (var item in listQuestionCategory) { category.Formula.Values.Add(item.Name); } ws.Cells["A:AZ"].AutoFitColumns(); Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment: filename=" + "ExamPaperTemplate.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); }