コード例 #1
0
        /// <summary>
        /// 用户解绑.学生解绑账号
        /// @author dwy
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns>true 解绑成功 false 解绑失败</returns>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.IClassService.DeleteCourseSelectionById(System.Int64,System.Int64)"/>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">未找到对应用户</exception>
        public void DeleteStudentAccount(long userId)
        {
            if (userId < 0)
            {
                throw new ArgumentException("userId格式错误");
            }
            var user = _db.UserInfo.Find(userId) ??
                       throw new UserNotFoundException();
            IList <ClassInfo>    courses = _classService.ListClassByUserId(userId);                    //根据学生ID获取班级列表
            IList <SeminarGroup> groups  = _seminarGroupService.ListSeminarGroupIdByStudentId(userId); //获取学生的所有讨论课小组

            foreach (SeminarGroup s in groups)
            {
                if (userId == _seminarGroupService.GetSeminarGroupLeaderByGroupId(s.Id)) //如果是组长
                {
                    _seminarGroupService.ResignLeaderById(s.Id, userId);                 //组长辞职
                }
                _seminarGroupService.DeleteSeminarGroupMemberById(s.Id, userId);         //在小组中删除该成员
            }
            foreach (ClassInfo c in courses)
            {
                FixGroup fixGroup = _fixGroupService.GetFixedGroupById(userId, c.Id); //找到学生所在的固定小组
                _fixGroupService.DeleteFixGroupUserById(fixGroup.Id, userId);         //将学生从固定小组中删去
                _classService.DeleteCourseSelectionById(userId, c.Id);                //学生按班级ID取消选择班级
            }

            _db.RemoveRange(_db.UserInfo.Where(u => u.Id == userId));//删除学生账号
            _db.SaveChanges();
        }
コード例 #2
0
        /// <summary>
        /// 用户解绑.学生解绑账号
        /// @author dwy
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <returns>true 解绑成功 false 解绑失败</returns>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.IClassService.DeleteCourseSelectionById(System.Int64,System.Int64)"/>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">未找到对应用户</exception>
        public void DeleteStudentAccount(long userId)
        {
            if (userId < 0)
            {
                throw new ArgumentException("userId格式错误");
            }
            var user = _db.UserInfo.Find(userId) ??
                       throw new UserNotFoundException();
            IList <ClassInfo> courses = _classService.ListClassByUserId(userId);//根据学生ID获取班级列表

            foreach (ClassInfo c in courses)
            {
                FixGroup fixGroup = _fixGroupService.GetFixedGroupById(userId, c.Id); //找到学生所在的固定小组
                _fixGroupService.DeleteFixGroupUserById(fixGroup.Id, userId);         //将学生从固定小组中删去
                _classService.DeleteCourseSelectionById(userId, c.Id);                //学生按班级ID取消选择班级
            }
            _db.RemoveRange(_db.UserInfo.Where(u => u.Id == userId));                 //删除学生账号
            _db.SaveChanges();
        }
コード例 #3
0
 public void DeleteTopicBySeminarId(long seminarId)
 {
     _db.RemoveRange(ListTopicBySeminarId(seminarId));
     _db.SaveChanges();
 }