Exemple #1
0
        public void testDeleteQuestionByExamId()
        {
            QuestionModel model = new QuestionModel();
            Assert.IsTrue(model.deleteQuestionByExamId(13)>0);


        }
Exemple #2
0
  public void testDeleteQuestion()
 {
    QuestionModel model = new QuestionModel();
    Assert.IsTrue(model.deleteQuestion(14)==1);
    
   
 }
Exemple #3
0
        public void testAddQuestion()
        {   
            QuestionModel model = new QuestionModel();
            int i = model.addQuesiton(0, "test", "test", "test", "test", 1);
            Assert.IsTrue(i > 0);

        }
 public ActionResult GetProblemDetail(int id)
 {
     var model = new QuestionModel();
     var data = model.getQuestionByID(id);
     var encoder = new JavaScriptSerializer();
     return Json(encoder.Serialize(data));
 }
        public ActionResult AddExam()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            Dictionary<string,String> ret = new Dictionary<string,string>();
            HttpPostedFileBase file =  Request.Files.Get("doc");
            if (file != null)
            {
                if (checkFileExt(file.FileName))
                {
                    ExamModel examModel= new ExamModel();
                    QuestionModel questionModel = new QuestionModel();
                    var docName = "~/upload/tmp.docx";
                    var examname = "";
                    file.SaveAs(Server.MapPath(docName));
                    try
                    {
                        ExamEntity examEntity = examModel.praseFromDoc(Server.MapPath(docName));
                        if (file.FileName.LastIndexOf('\\') != -1)
                        {
                            examname = file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1, file.FileName.Length - 1 - file.FileName.LastIndexOf('\\'));
                        }
                        else
                        {
                            examname = file.FileName;
                        }
                        int examId = examModel.addExam(examEntity.time, examEntity.sNumber, examEntity.mNumber, examEntity.tNumber, examEntity.sScore, examEntity.mScore, examEntity.tScore, 0, examname.Substring(0, examname.Length - 5));
                        int type = -1;
                        int count = 1;
                        foreach (QuestionEntity q in examEntity.sc)
                        {
                            
                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg", count);
                                 imageDir = string.Format("~/upload/{0}/sc", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                           
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                        count = 1;
                        foreach (QuestionEntity q in examEntity.mc)
                        {

                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg",count);
                                 imageDir = string.Format("~/upload/{0}/mc", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                            
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                        count = 1;
                        foreach (QuestionEntity q in examEntity.tf)
                        {

                            switch (q.type)
                            {
                                case "SC":
                                    type = 0;
                                    break;
                                case "MC":
                                    type = 1;
                                    break;
                                case "TF":
                                    type = 2;
                                    break;
                            }
                             var imageDir = "";
                             var imageName = "";
                             if (q.image != null)
                             {
                                 imageName = string.Format("/{0}.jpg", count);
                                 imageDir = string.Format("~/upload/{0}/tf", examId, count);
                                 if(!Directory.Exists(Server.MapPath(imageDir)))
                                 {
                                     Directory.CreateDirectory(Server.MapPath(imageDir));
                                 }
                                
                                 q.image.Save(Server.MapPath(imageDir+imageName));
                                 count = count + 1;
                             }
                            
                            var choiceJson = new JavaScriptSerializer().Serialize(q.choices);
                            questionModel.addQuesiton(type, q.ans, choiceJson, imageDir+imageName, q.statement, examId);
                        }
                    

                    }
                    catch(Exception e)
                    {
                        System.IO.File.Delete(Server.MapPath(docName));
                        ret.Add("status", "failed");
                        ret.Add("error", "parse doc error");
                        return Json(ret);
                    }
                    System.IO.File.Delete(Server.MapPath(docName));
                    ret.Add("status", "success");
                    ret.Add("filename", examname);
                    return Json(ret);
                }
                else
                {
                    
                    ret.Add("status", "failed");
                    ret.Add("error", "file type not allowed");
                    return Json(ret);
                }
            }
            else
            {
              
                ret.Add("status", "failed");
                ret.Add("error", "no files");
                return Json(ret);
            }
           
        }
 public ActionResult DeleteExam()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     Dictionary<string,string> response = new Dictionary<string,string>();
     ExamModel examModel = new ExamModel();
     QuestionModel questionModel = new QuestionModel();
     int id;
     try
     {
         id = int.Parse(Request["id"]);
         if (Directory.Exists(Server.MapPath(string.Format("~/upload/{0}", id))))
         {
             Directory.Delete(Server.MapPath(string.Format("~/upload/{0}", id)),true);
         }
         int questionCol = questionModel.deleteQuestionByExamId(id);
         int examCol = examModel.deleteExam(id);
         if (questionCol > 0 && examCol > 0)
         {
             response.Add("status", "success");
         }
         else
         {
             response.Add("status", "failed");
             response.Add("error", "something wrong when delete the record from database!");
         }
     }
     catch 
     {
         response.Add("status", "failed");
         response.Add("error", "bad id!");
     }
     return Json(response);
 }
Exemple #7
0
 public List<QuestionEntity> genExam(int id)
 {
     var questionModel = new QuestionModel();
     var exam = getExamById(id);
     var sc = randSelect( questionModel.getSCQuestionByExam(id) , exam.sNumber);
     var mc = randSelect( questionModel.getMCQuestionByExam(id) , exam.mNumber);
     var tf = randSelect( questionModel.getTFQuestionByExam(id) , exam.tNumber);
     var res = new List<QuestionEntity>();
     res.AddRange(sc);
     res.AddRange(mc);
     res.AddRange(tf);
     return res;
 }