コード例 #1
0
        public ActionResult GenerateExamPost(int?ExamCoreStudentGroupID, int?questionNumber)
        {
            try
            {
                if (ExamCoreStudentGroupID != null && questionNumber != null)
                {
                    var examCoreStudentGroup = _examCoreStudentGroupService.GetByID((int)ExamCoreStudentGroupID);
                    var core = _examCoreService.Find(examCoreStudentGroup.ExamCoreID);
                    var studentsGroupsStudentsIDList = _studentGroupService.GetStudentsGroupStudentID(examCoreStudentGroup.StudentGroupID);
                    var random = new Random();
                    var path   = Request.MapPath("~/GeneratedExams");

                    if (!Directory.Exists(Request.MapPath("~/GeneratedExams")))
                    {
                        Directory.CreateDirectory(path);
                    }
                    DocumentCreator creator = new DocumentCreator(path);
                    foreach (var studentGroupStudentID in studentsGroupsStudentsIDList)
                    {
                        var generatedExamDTO = GenerateExamForStudent2(core, studentGroupStudentID, (int)questionNumber, (int)ExamCoreStudentGroupID);
                        creator.AddExamToGenerate(generatedExamDTO);
                    }
                    creator.Generate();

                    ArchiveUnZiper.PackFileToArchive(path + "//" + PDFHelpers.GetMD5(creator.PDFDocuments.FirstOrDefault()?.Filename) + ".zip", creator.PDFDocuments.Select(x => x.Filepath + x.Filename).ToList());

                    foreach (var pdfDocument in creator.PDFDocuments)
                    {
                        _answerPositionService.InsertRange(pdfDocument.ExamID, Mapper.Map <List <AnswerPosition> >(pdfDocument.ExamAnswerPositions));
                    }
                    _examCoreStudentGroupService.SetExamArchivePath(examCoreStudentGroup.Id, PDFHelpers.GetMD5(creator.PDFDocuments.FirstOrDefault()?.Filename) + ".zip");
                    return(RedirectToAction("Details", "StudentGroups", new { id = (int)examCoreStudentGroup.StudentGroupID }));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("Index", "StudentGroups"));
            }
            return(RedirectToAction("Index", "StudentGroups"));
        }