Exemplo n.º 1
0
        public ActionResult AddModule(FormCollection form)
        {
            int moduleTag = Convert.ToInt32(Request.QueryString["moduleTag"]);
            int CId = Convert.ToInt32(form["CourseId"]);
            //int ModuleId = Convert.ToInt32(form["ModuleId"]); ///完成修改
            HttpPostedFileBase hpfb = Request.Files["teacherUpLoad"];
            string filePath = "";
            try
            {
                if (hpfb.ContentLength > 0)
                {
                    Common.UpLoad upLoad = new Common.UpLoad();
                    filePath = upLoad.TeacherSaveFile(hpfb);
                }

                Module module = db.Module.Where(m => m.ModuleTag == moduleTag && m.CourseId == CId).FirstOrDefault();
                //如果可以查询到module 说明模块已存在,即是修改,否则是建立新的模块
                if (module == null)
                {
                    module = new Module()
                    {
                        ModuleTag = moduleTag,
                        DeadlineTime = form["DeadlineTime"],
                        ModuleContent = form["ModuleContent"],
                        ModuleTitle = form["ModuleTitle"],
                        CourseId = CId,
                        ModuleFilePath = filePath
                    };
                    module = db.Module.Add(module);
                    int moduleId = module.Id;
                    string[] keys = form.AllKeys;
                    if (form["SelectQ1"] != "" && form["SelectQ1"] != null)
                    {
                        for (int i = 1; i <= 10; i++)//默认只能有十个选择
                        {
                            if (keys.Contains<string>("SelectQ" + i))
                            {
                                PaperQuestion question = new PaperQuestion()
                                {
                                    QTitle = form["SelectQ" + i],
                                    QuestionType = int.Parse(form["type" + i]),
                                    A = form["SelectQ" + i + "A"],
                                    B = form["SelectQ" + i + "B"],
                                    C = form["SelectQ" + i + "C"],
                                    D = form["SelectQ" + i + "D"],
                                    Answer = form["SelectAnswer" + i],
                                    MouduleId = moduleId,
                                    CourseId = CId,
                                    ModuleTag = moduleTag
                                };
                                db.PaperQuestion.Add(question);
                            }
                            else
                                break;
                        }
                    }
                    if (form["BlankQ1"] != "" && form["BlankQ1"] != null)
                    {
                        for (int i = 1; i <= 5; i++)//默认只能有五个填空
                        {
                            if (keys.Contains<string>("BlankQ" + i))
                            {
                                PaperQuestion question = new PaperQuestion()
                                {
                                    QTitle = form["BlankQ" + i],
                                    Answer = form["BlankAnswer" + i],
                                    QuestionType=2,
                                    MouduleId = moduleId,
                                    CourseId = CId,
                                    ModuleTag = moduleTag
                                };
                                db.PaperQuestion.Add(question);
                            }
                            else
                                break;
                        }
                    }
                }
                //修改模块信息
                else
                {
                    //todo ---------修改试题!!!!
                    module.DeadlineTime = form["DeadlineTime"];
                    module.ModuleContent = form["ModuleContent"];
                    module.ModuleTitle = form["ModuleTitle"];
                    if (!string.IsNullOrEmpty(filePath))
                    { module.ModuleFilePath = filePath; }
                }

                db.SaveChanges();

            }
            catch (Exception)
            {
                ViewBag.TagMSG = "Error";
                throw;
            }

            ViewBag.TagMSG = "OK";

            return RedirectToAction("CoursesDetail", "CourseManage", new { id = CId });
        }
Exemplo n.º 2
0
        public ActionResult AddModule(FormCollection form)
        {
            int moduleTag = Convert.ToInt32(Request.QueryString["moduleTag"]);
            int CId       = Convert.ToInt32(form["CourseId"]);
            //int ModuleId = Convert.ToInt32(form["ModuleId"]); ///完成修改
            HttpPostedFileBase hpfb     = Request.Files["teacherUpLoad"];
            string             filePath = "";

            try
            {
                if (hpfb.ContentLength > 0)
                {
                    Common.UpLoad upLoad = new Common.UpLoad();
                    filePath = upLoad.TeacherSaveFile(hpfb);
                }

                Module module = db.Module.Where(m => m.ModuleTag == moduleTag && m.CourseId == CId).FirstOrDefault();
                //如果可以查询到module 说明模块已存在,即是修改,否则是建立新的模块
                if (module == null)
                {
                    module = new Module()
                    {
                        ModuleTag      = moduleTag,
                        DeadlineTime   = form["DeadlineTime"],
                        ModuleContent  = form["ModuleContent"],
                        ModuleTitle    = form["ModuleTitle"],
                        CourseId       = CId,
                        ModuleFilePath = filePath
                    };
                    module = db.Module.Add(module);
                    int      moduleId = module.Id;
                    string[] keys     = form.AllKeys;
                    if (form["SelectQ1"] != "" && form["SelectQ1"] != null)
                    {
                        for (int i = 1; i <= 10; i++)//默认只能有十个选择
                        {
                            if (keys.Contains <string>("SelectQ" + i))
                            {
                                PaperQuestion question = new PaperQuestion()
                                {
                                    QTitle       = form["SelectQ" + i],
                                    QuestionType = int.Parse(form["type" + i]),
                                    A            = form["SelectQ" + i + "A"],
                                    B            = form["SelectQ" + i + "B"],
                                    C            = form["SelectQ" + i + "C"],
                                    D            = form["SelectQ" + i + "D"],
                                    Answer       = form["SelectAnswer" + i],
                                    MouduleId    = moduleId,
                                    CourseId     = CId,
                                    ModuleTag    = moduleTag
                                };
                                db.PaperQuestion.Add(question);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    if (form["BlankQ1"] != "" && form["BlankQ1"] != null)
                    {
                        for (int i = 1; i <= 5; i++)//默认只能有五个填空
                        {
                            if (keys.Contains <string>("BlankQ" + i))
                            {
                                PaperQuestion question = new PaperQuestion()
                                {
                                    QTitle       = form["BlankQ" + i],
                                    Answer       = form["BlankAnswer" + i],
                                    QuestionType = 2,
                                    MouduleId    = moduleId,
                                    CourseId     = CId,
                                    ModuleTag    = moduleTag
                                };
                                db.PaperQuestion.Add(question);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                //修改模块信息
                else
                {
                    //todo ---------修改试题!!!!
                    module.DeadlineTime  = form["DeadlineTime"];
                    module.ModuleContent = form["ModuleContent"];
                    module.ModuleTitle   = form["ModuleTitle"];
                    if (!string.IsNullOrEmpty(filePath))
                    {
                        module.ModuleFilePath = filePath;
                    }
                }

                db.SaveChanges();
            }
            catch (Exception)
            {
                ViewBag.TagMSG = "Error";
                throw;
            }

            ViewBag.TagMSG = "OK";


            return(RedirectToAction("CoursesDetail", "CourseManage", new { id = CId }));
        }
Exemplo n.º 3
0
        public ActionResult FinishModule(FormCollection form)
        {
            int    moduleTag = Convert.ToInt32(Request.QueryString["moduleTag"]);
            string CId       = form["CourseId"].Trim();

            HttpPostedFileBase hpfb     = Request.Files["studentPath"];
            string             filePath = "";

            if (hpfb.ContentLength > 0)
            {
                Common.UpLoad upLoad = new Common.UpLoad();
                filePath = upLoad.StudentSaveFile(hpfb);
            }

            int CourseId = 0;

            if (CId != null && CId != "")
            {
                CourseId = Convert.ToInt32(CId);
            }

            //完成课后习题答案的提交和成绩

            //先查询出当前模块的所有题目ID
            List <PaperQuestion> pQuestionList = db.PaperQuestion.Where(c => c.CourseId == CourseId && c.ModuleTag == moduleTag).ToList();
            //再根据所有questionId查找所有提交过来的form,如果是单选就直接查值,如果是多选就split那个form值
            PaperStudentAnswer pAnswer = null;

            foreach (PaperQuestion p in pQuestionList)
            {
                pAnswer = new PaperStudentAnswer()
                {
                    StudentId  = new Guid(studentId),
                    CourseId   = CourseId,
                    MouduleTag = moduleTag,
                };
                string Answer;           //传来的form值
                if (p.QuestionType == 0) //单选
                {
                    Answer = Request.Form[p.Id + "&Answer"].ToString();
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                    {
                        pAnswer.AnswerScore = 0;
                    }
                }
                else if (p.QuestionType == 1)//多选
                {
                    Answer = Request.Form[p.Id + "&Answer"].ToString();
                    //--todo split需要完成
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                    {
                        pAnswer.AnswerScore = 0;
                    }
                }
                else //填空
                {
                    Answer = Request.Form[p.Id + "&Answer"].ToString();
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                    {
                        pAnswer.AnswerScore = 0;
                    }
                }
                pAnswer.MouduleId  = p.MouduleId;
                pAnswer.QuestionId = p.Id;
                pAnswer.Answer     = Answer;
                db.PaperStudentAnswer.Add(pAnswer);
            }



            //List<PaperStudentAnswer> pAnswerList = db.PaperStudentAnswer.Where(c=>c.StudentId==new Guid(studentId)&&c.CourseId==CourseId&&c.==).ToList();

            StudentWork work  = null;
            StudentInfo sInfo = db.StudentInfo.Where(s => s.Id == new Guid(studentId)).FirstOrDefault();

            work = new StudentWork()
            {
                CourseId       = Convert.ToInt32(form["CourseId"]),
                ModuleTag      = Convert.ToInt32(Request.QueryString["moduleTag"]),
                WorkContent    = form["WorkContent"],
                WorkTime       = DateTime.Now.ToString(),
                StudentId      = new Guid(studentId),
                StudentAccount = sInfo.Account,
                WorkFilePath   = filePath
            };
            db.StudentWork.Add(work);
            db.SaveChanges();

            return(RedirectToAction("StudentEnterCourse", new { id = CourseId }));
        }
Exemplo n.º 4
0
        public ActionResult FinishModule(FormCollection form)
        {
            int moduleTag = Convert.ToInt32(Request.QueryString["moduleTag"]);
            string CId = form["CourseId"].Trim();

            HttpPostedFileBase hpfb = Request.Files["studentPath"];
            string filePath = "";
            if (hpfb.ContentLength > 0)
            {
                Common.UpLoad upLoad = new Common.UpLoad();
                filePath = upLoad.StudentSaveFile(hpfb);
            }

            int CourseId = 0;
            if (CId != null && CId != "")
            {
                CourseId = Convert.ToInt32(CId);
            }

            //完成课后习题答案的提交和成绩

            //先查询出当前模块的所有题目ID
            List<PaperQuestion> pQuestionList = db.PaperQuestion.Where(c => c.CourseId == CourseId && c.ModuleTag == moduleTag).ToList();
            //再根据所有questionId查找所有提交过来的form,如果是单选就直接查值,如果是多选就split那个form值
            PaperStudentAnswer pAnswer = null;

            foreach (PaperQuestion p in pQuestionList)
            {
                pAnswer = new PaperStudentAnswer()
                {
                    StudentId = new Guid(studentId),
                    CourseId = CourseId,
                    MouduleTag = moduleTag,
                };
                string Answer;//传来的form值
                if (p.QuestionType == 0)//单选
                {
                    Answer = Request.Form[p.Id + "&Answer"].ToString();
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                        pAnswer.AnswerScore = 0;
                }
                else if (p.QuestionType == 1)//多选
                {
                    Answer = Request.Form[p.Id + "&Answer"].ToString();
                    //--todo split需要完成
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                        pAnswer.AnswerScore = 0;
                }
                else //填空
                {
                    Answer = Request.Form[p.Id+"&Answer"].ToString();
                    if (p.Answer == Answer)
                    {
                        pAnswer.AnswerScore = 4;
                    }
                    else
                        pAnswer.AnswerScore = 0;
                }
                pAnswer.MouduleId = p.MouduleId;
                pAnswer.QuestionId = p.Id;
                pAnswer.Answer = Answer;
                db.PaperStudentAnswer.Add(pAnswer);
            }

            //List<PaperStudentAnswer> pAnswerList = db.PaperStudentAnswer.Where(c=>c.StudentId==new Guid(studentId)&&c.CourseId==CourseId&&c.==).ToList();

            StudentWork work = null;
            StudentInfo sInfo = db.StudentInfo.Where(s => s.Id == new Guid(studentId)).FirstOrDefault();
            work = new StudentWork()
            {
                CourseId = Convert.ToInt32(form["CourseId"]),
                ModuleTag = Convert.ToInt32(Request.QueryString["moduleTag"]),
                WorkContent = form["WorkContent"],
                WorkTime = DateTime.Now.ToString(),
                StudentId = new Guid(studentId),
                StudentAccount = sInfo.Account,
                WorkFilePath = filePath

            };
            db.StudentWork.Add(work);
            db.SaveChanges();

            return RedirectToAction("StudentEnterCourse", new { id = CourseId });
        }