示例#1
0
        /// <summary>
        /// 取消写生排课
        /// <para>作    者:郭伟佳</para>
        /// <para>创建时间:2018-11-28</para>
        /// </summary>
        /// <exception cref="AMS.Core.BussinessException">
        /// 异常ID:
        /// 13. 系统不存在该写生课信息
        /// 14. 该学期已结束,不可取消
        /// 34. 写生课已取消
        /// </exception>
        public void Cancel()
        {
            lock (LocalThreadLock.GetLockKeyName(LockKeyNames.LOCK_LIFE_CLASS, _lifeClassId.ToString()))
            {
                var lifeClassInfo = _repository.Value.GetLifeClassInfo(_lifeClassId);

                //1、根据写生课Id,获取写生课对应的课次基础信息的课程Id列表
                var studentLessonInfoList = _timLessonRepository.Value.GetStudentLessonListAsync(_schoolId, new List <long> {
                    _lifeClassId
                });
                var lessonIdList = studentLessonInfoList.Where(a => a.Status == (int)LessonUltimateStatus.Normal).Select(a => a.LessonId).ToList();

                //2、校验
                CheckDataBeforeCancel(lifeClassInfo, lessonIdList);

                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    try
                    {
                        unitOfWork.BeginTransaction(IsolationLevel.Snapshot);

                        //3、取消写生课Id对应的所有学生的课次
                        CancelLifeClass(unitOfWork, lifeClassInfo, lessonIdList);

                        //4、删除对应的写生课
                        TblTimLifeClassRepository lifeClassRepository = unitOfWork.GetCustomRepository <TblTimLifeClassRepository, TblTimLifeClass>();
                        lifeClassRepository.DeleteLifeClassById(_lifeClassId);

                        unitOfWork.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.RollbackTransaction();
                        throw ex;
                    }
                }
            }
        }