Ejemplo n.º 1
0
        public bool ClearWrongSubject(int bookId, int wrongSubjectId, StudyWrongStatusEnum toStatus)
        {
            bool result = false;

            if (toStatus == StudyWrongStatusEnum.消除中 || toStatus == StudyWrongStatusEnum.已消除 || toStatus == StudyWrongStatusEnum.已做对)
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        bool clearSubject = StudentWrongSubjectRepository.ClearSubject(wrongSubjectId, toStatus);
                        bool clearBook    = StudentWrongBookRepository.RefreshStatus(bookId);
                        //if (toStatus == StudyWrongStatusEnum.已消除)
                        //{
                        //    clearBook = StudentWrongBookRepository.RefreshStatus(bookId);
                        //}
                        result = clearSubject && clearBook;
                        if (result)
                        {
                            scope.Complete();
                        }
                        else
                        {
                            RollbackTran();
                        }
                    }
                    catch (Exception)
                    {
                        RollbackTran();
                        throw;
                    }
                }
            }
            else
            {
                result = StudentWrongSubjectRepository.IncrementRemoveCount(wrongSubjectId, 1);
            }
            return(result);
        }
Ejemplo n.º 2
0
 public Yw_StudentWrongBook GetBookByStudentAndStudy(int studentId, int courseId, int lessonId, int progressId, int taskId)
 {
     return(StudentWrongBookRepository.GetByStudentAndStudy(studentId, courseId, lessonId, progressId, taskId));
 }
Ejemplo n.º 3
0
 public List <DtoStudentWrongBookInfo> GetBookList(DtoStudentWrongSearch search)
 {
     return(StudentWrongBookRepository.GetBookList(search));
 }
Ejemplo n.º 4
0
        public bool SaveWrongBook(List <StudentAnswerCard> answerCard, DtoStudentWrongBook wrongBook)
        {
            bool result       = false;
            var  studyProcess = StudentStudyBll.GetProgressByStudentCourse(wrongBook.StudentId, wrongBook.CourseId);
            int  schoolId     = studyProcess == null ? 0 : studyProcess.Yps_SchoolId;
            int  classId      = studyProcess == null ? 0 : studyProcess.Yps_ClassId;
            List <StudentAnswerBase>      answers     = answerCard.SelectMany(s => s.AnswerCollection).ToList();
            List <Yw_StudentWrongSubject> listSubject = new List <Yw_StudentWrongSubject>();

            if (answers.Any(s => s.SubjectId <= 0))
            {
                throw new AbhsException(ErrorCodeEnum.ParameterInvalid, AbhsErrorMsg.ConstParameterInvalid);
            }
            answers.ForEach(a =>
            {
                if (CheckAnswerNeedRecordWorng(a))
                {
                    Yw_StudentWrongSubjectExt tmp = new Yw_StudentWrongSubjectExt();
                    tmp.Yws_CourseId       = wrongBook.CourseId;
                    tmp.Yws_CreateTime     = DateTime.Now;
                    tmp.Yws_KnowledgeId    = a.KnowledgeId;
                    tmp.Yws_LessonId       = wrongBook.LessonId;
                    tmp.Yws_RemoveTryCount = 0;
                    tmp.Yws_Source         = (int)wrongBook.Source;
                    tmp.Yws_Status         = (int)StudyWrongStatusEnum.未消除;
                    tmp.Yws_Answer_Obj     = a;
                    tmp.Yws_StudentId      = wrongBook.StudentId;
                    tmp.Yws_SubjectType    = a.Type;
                    tmp.Yws_UpdateTime     = DateTime.Now;
                    tmp.Yws_WrongBookId    = 0;
                    tmp.Yws_WrongSubjectId = a.SubjectId;

                    listSubject.Add(tmp);
                }
            });
            if (listSubject.Count == 0)
            {
                return(true);
            }
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    Yw_StudentWrongBook bookModel = GetBookByStudentAndStudy(wrongBook.StudentId, wrongBook.CourseId, wrongBook.LessonId, wrongBook.LessonProgressId, wrongBook.StudyTaskId);
                    bool saveSubject         = false;
                    bool saveBook            = false;
                    int  WrongCount          = 0;
                    int  WrongKnowledgeCount = 0;

                    #region 获取要插入的错题及错题数的计算
                    if (bookModel != null)
                    {
                        List <Yw_StudentWrongSubject> oldSubjectList = GetSubjectByBookId(bookModel.Ywb_Id);
                        listSubject = listSubject.ExceptExt(oldSubjectList, l => l.Yws_WrongSubjectId)
                                      //.Where(s =>
                                      // {
                                      //     return !oldSubjectList.Exists(o => o.Yws_WrongSubjectId == s.Yws_WrongSubjectId);
                                      // })
                                      .Select(s => s)
                                      .ToList();
                        WrongCount          = bookModel.Yws_WrongCount + listSubject.Select(s => s.Yws_WrongSubjectId).Distinct().Count();
                        WrongKnowledgeCount = (from o in oldSubjectList
                                               where o.Yws_Status == (int)StudyWrongStatusEnum.未消除 && o.Yws_KnowledgeId > 0
                                               select o.Yws_KnowledgeId)
                                              .Concat(from n in listSubject where n.Yws_KnowledgeId > 0 select n.Yws_KnowledgeId)
                                              .Distinct().Count();
                    }
                    else
                    {
                        WrongCount          = listSubject.Select(s => s.Yws_WrongSubjectId).Distinct().Count();
                        WrongKnowledgeCount = listSubject.Where(s => s.Yws_KnowledgeId > 0).Select(s => s.Yws_KnowledgeId).Distinct().Count();
                    }
                    #endregion

                    #region save错题本
                    if (bookModel != null)
                    {
                        bookModel.Yws_WrongCount          = WrongCount;
                        bookModel.Yws_WrongKnowledgeCount = WrongKnowledgeCount;
                        bookModel.Yws_UpdateTime          = DateTime.Now;
                        saveBook = StudentWrongBookRepository.Update(bookModel);
                    }
                    else
                    {
                        bookModel = new Yw_StudentWrongBook();
                        bookModel.Ywb_CourseId            = wrongBook.CourseId;
                        bookModel.Ywb_LessonId            = wrongBook.LessonId;
                        bookModel.Ywb_LessonProgressId    = wrongBook.LessonProgressId;
                        bookModel.Ywb_StudentId           = wrongBook.StudentId;
                        bookModel.Ywb_StudyTaskId         = wrongBook.StudyTaskId;
                        bookModel.Yws_ClassId             = classId;
                        bookModel.Yws_CreateTime          = DateTime.Now;
                        bookModel.Yws_RemoveCount         = 0;
                        bookModel.Yws_SchoolId            = schoolId;
                        bookModel.Yws_Source              = (int)wrongBook.Source;
                        bookModel.Yws_Status              = (int)StudyWrongStatusEnum.未消除;
                        bookModel.Yws_UpdateTime          = DateTime.Now;
                        bookModel.Yws_WrongCount          = WrongCount;
                        bookModel.Yws_WrongKnowledgeCount = WrongKnowledgeCount;
                        bookModel.Ywb_Id = StudentWrongBookRepository.Insert(bookModel);
                        saveBook         = bookModel.Ywb_Id > 0;
                    }
                    listSubject.ForEach(s => s.Yws_WrongBookId = bookModel.Ywb_Id);
                    #endregion

                    #region save错题详情
                    saveSubject = InsertSubjectList(listSubject);
                    #endregion
                    result = saveBook && saveSubject;
                    if (result)
                    {
                        scope.Complete();
                    }
                    else
                    {
                        RollbackTran();
                    }
                }
                catch (Exception)
                {
                    RollbackTran();
                    throw;
                }
            }

            return(result);
        }