public ActionResult Validate(HttpPostedFileBase FileUpload)
        {
            try
            {
                if (FileUpload != null)
                {
                    string path = Request.MapPath("~/UserBitmaps");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    string fullPath = path + "//" + FileUpload.FileName + PDFHelpers.GetMD5(new Random().Next().ToString());;
                    FileUpload.SaveAs(fullPath);

                    var bitmaps   = ArchiveUnZiper.GetBitmapsFromZipArchive(fullPath);
                    var validator = new DocumentValidator(bitmaps);
                    var examIDs   = validator.GetExamIDs();
                    if (examIDs.Count == 1 && examIDs.First() == 0)
                    {
                        return(View());
                    }

                    foreach (var examID in examIDs)
                    {
                        var egzaminAP = _answerPositionService.GetAllAnswersPositionsByExamID(examID);

                        var examResults = validator.CheckExam(examID, Mapper.Map <List <AnswerPositionDTO> >(egzaminAP));

                        var studentID = _resultService.GetStudentIDByExamID(examID);
                        if (studentID != null)
                        {
                            examResults.StudentID = (int)studentID;
                        }
                        _resultService.DeletePreviousResults(examID);
                        _resultService.Insert(Mapper.Map <Result>(examResults));
                    }

                    if (examIDs.Count > 0)
                    {
                        _resultService.SetIsValidatetFlagByExamID(examIDs.FirstOrDefault());
                        var examCoreStudentGroupID = _generatedExamService.GetByID(examIDs.FirstOrDefault()).ExamCoreStudentGroupID;

                        return(Json(new { success = true, failure = false, responseText = "Success.", responseHref = Url.Action("Index/", "Results", new { examCoreStudentGroupID = examCoreStudentGroupID.ToString() }) }, JsonRequestBehavior.AllowGet));
                    }
                }
                return(Json(new { success = false, failure = true, responseText = "Error during validating exam." }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, failure = true, responseText = "Error during validating exam." }, JsonRequestBehavior.AllowGet));
            }
        }
        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"));
        }
        public ActionResult CheckUploadExams(HttpPostedFileBase FileUpload)
        {
            string path     = Request.MapPath("~/UserBitmaps");
            string fullPath = path + "//" + FileUpload.FileName + PDFHelpers.GetMD5(new Random().Next().ToString());

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            FileUpload.SaveAs(fullPath);

            var bitmaps   = ArchiveUnZiper.GetBitmapsFromZipArchive(fullPath);
            var validator = new DocumentValidator(bitmaps);
            var examIDs   = validator.GetExamIDs();

            foreach (var item in examIDs)
            {
                var egzaminAP   = _answerPositionService.GetAllAnswersPositionsByExamID(item);
                var examResults = validator.CheckExam(item, Mapper.Map <List <AnswerPositionDTO> >(egzaminAP));
            }
            return(RedirectToAction("Details", "StudentGroups", new { id = 0 }));
        }