/// <summary> /// 给章节添加题目 /// </summary> /// <returns></returns> public bool AddChapterQuestions(ChapterPostModel model) { W_Chapter paper = Orm.Single <W_Chapter>(x => x.ID == model.ChapterID); if (paper == null) { throw new ApiException("章节不存在或者已删除"); } SqlMapper.BeginTransaction(); try { foreach (int questionId in model.questionIds) { Orm.Insert <W_Chapter_Question>(new W_Chapter_Question() { Chapter_ID = model.ChapterID, Question_ID = questionId }); } SqlMapper.CommitTransaction(); } catch { SqlMapper.RollBackTransaction(); return(false); } return(true); }
public bool AddChapter(W_Chapter model) { if (string.IsNullOrEmpty(model.Name)) { throw new ApiException("章节名称不能为空"); } return(Orm.Insert(model) > 0); }
public bool UpdateChapter(W_Chapter model) { if (model == null) { throw new ApiException("对象不能为空"); //当出现异常后,可以直接抛ApiException,拦截器将会拦截异常,并格式化输出 } W_Chapter oldModel = Orm.Single <W_Chapter>(x => x.ID == model.ID); model.AddPerson = oldModel.AddPerson; model.AddTime = oldModel.AddTime; return(Orm.Update(model) > 0); }
public dynamic UpdateChapter(W_Chapter model) { if (model != null) { if (mapper.UpdateChapter(model)) { return(Success("操作成功")); } else { return(Success("操作失败")); } } else { return(Success("操作失败")); } }
public dynamic Enabledisable(W_Chapter model) { //如果将要启用的章节是子章节,需要先启用父章节 if (model.Valid == 1) { W_Chapter chapter = Orm.Single <W_Chapter>(x => x.ID == model.ID); if (chapter == null) { throw new ApiException("章节已删除或者不存在"); } if (chapter.CID > 0) { W_Chapter parent = Orm.Single <W_Chapter>(x => x.ID == chapter.CID); if (parent.Valid == 0) { throw new ApiException("请先启用父章节"); } } } return(SqlMapper.Update("Enabledisable", new { id = model.ID, valid = model.Valid }) > 0); }
public string GetPraticeInfo(int chapterId, int storeId) { W_Chapter chapter = Orm.Single <W_Chapter>(x => x.ID == chapterId); if (chapter == null) { return("未知章节练习"); } W_Chapter parent = Orm.Single <W_Chapter>(x => x.ID == chapter.CID); if (parent == null) { return("未知章节练习"); } W_QuestionStore store = Orm.Single <W_QuestionStore>(x => x.ID == storeId); if (store == null) { return("未知章节练习"); } return(store.Name + " " + parent.Name + " " + chapter.Name); }
public dynamic AddChapter(W_Chapter model) { if (model != null) { model.AddPerson = this.AccountID; model.AddTime = DateTime.Now.ToString(); ChapterMapper mapper = new ChapterMapper(); var dict = mapper.AddChapter(model); if (dict) { return(Success("操作成功")); } else { return(Success("操作失败")); } } else { return(Success("操作失败")); } }
public dynamic DeleteChapter(W_Chapter model) { W_Chapter oldModel = Orm.Single <W_Chapter>(x => x.ID == model.ID); if (oldModel == null) { throw new ApiException("章节已删除或者不存在"); } if (oldModel.Valid == 1) { throw new ApiException("已启用的章节无法删除"); } List <W_Chapter> newmodel = Orm.Select <W_Chapter>(x => x.CID == model.ID); if (newmodel.Count > 0) { throw new ApiException("请检查章下面是否存在节"); } if (Orm.Select <W_Chapter_Question>(x => x.Chapter_ID == model.ID).Count > 0) { throw new ApiException("该章节包含章节练习,不能删除"); } return(Orm.Delete <W_Chapter>(x => x.ID == model.ID)); }
/// <summary> /// 继续做题 做题记录页面进来,继续/重新做题 继续做题:继续原来未完成的做题记录 重新做题:开始新的做题记录,题目和原做题记录题目一致(刷新页面确保逻辑一致) /// </summary> /// <param name="ID"></param> /// <param name="stuId"></param> /// <returns></returns> public dynamic ContinueChapterPractice(int ID, string stuId) { PracticeModel rtn = new PracticeModel(); W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == ID); if (cp == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = stuId }).ToList(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList(); //题目笔记列表 if (result.Valid == 1) //重新做题 { W_ChapterPractice cp2 = Orm.Single <W_ChapterPractice>(x => x.Source == cp.Source && x.Status == 0); //重新做题页面刷新 if (cp2 == null) { string[] str = cp.Source.Split('_'); if (str.Length != 6) { throw new ApiException("练习记录数据有误"); } W_ChapterPractice model = new W_ChapterPractice(); model.QuestionStore_ID = int.Parse(str[0]); model.AddTime = DateTime.Now; model.StuId = stuId; //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID.ToString() == str[1]).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = cp.Source; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult res = new W_DoExamResult(); res.StuId = model.StuId; res.BusType = 1;//章节练习 res.BusID = practiceId; res.BeginTime = model.AddTime; res.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(res, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } else { W_DoExamResult result2 = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp2.ID); if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result2.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result2.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result2); } } else { if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result); } return(rtn); }
/// <summary> /// 创建章节练习 /// </summary> /// <param name="model"></param> /// <returns></returns> public PracticeModel CreateChapterPractice(W_ChapterPractice model, int chapterId, string questionType, int questionCount, int questionSource) { PracticeModel rtn = new PracticeModel(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == model.StuId).ToList();//题目笔记列表 //判断是重新生成章节练习还是继续之前的章节练习 W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.Source == model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId && x.Status == 0); if (cp != null)//继续做题 { rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); if (result == null) { throw new ApiException("练习有误,请刷新重试"); } rtn.resultId = result.ID; List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = model.StuId }).ToList(); foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = model.AddTime; Orm.Update <W_DoExamResult>(result); } else//重新生成 { List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeQuestion", new { chapterId, questionType, questionCount, questionSource, stuId = model.StuId }).ToList(); if (list.Count == 0) { throw new ApiException("没有更多的试题"); } //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID == chapterId).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult result = new W_DoExamResult(); result.StuId = model.StuId; result.BusType = 1;//章节练习 result.BusID = practiceId; result.BeginTime = model.AddTime; result.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(result, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } return(rtn); }
public dynamic DeleteChapter(W_Chapter model) { return(Success(mapper.DeleteChapter(model))); }
public dynamic Enabledisable(W_Chapter model) { return(Success(mapper.Enabledisable(model) ? "操作成功" : "操作失败")); }