/// <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();
        }
Example #2
0
 public IActionResult GetUserClassGroupByClassId([FromRoute] long classId)
 {
     try
     {
         var user = _userService.GetUserByUserId(User.Id());
         if (user.Type == Shared.Models.Type.Teacher)
         {
             IList <FixGroup> groups = _fixGroupService.ListFixGroupByClassId(classId);
             return(Json(groups.Select(g =>
                                       new
             {
                 leader = new
                 {
                     id = g.LeaderId,
                     name = _userService.GetUserByUserId(g.LeaderId ?? 0).Name,
                     number = _userService.GetUserByUserId(g.LeaderId ?? 0).Number
                 },
                 member = _fixGroupService.ListFixGroupMemberByGroupId(g.Id).Select(m => new
                 {
                     id = m.Id,
                     name = m.Name,
                     number = m.Number
                 })
             }
                                       )));
         }
         else
         {
             var fixGroup = _fixGroupService.GetFixedGroupById(User.Id(), classId);
             var leader   = fixGroup.Leader ?? _userService.GetUserByUserId(fixGroup.LeaderId ?? 0);
             var members  = _fixGroupService.ListFixGroupMemberByGroupId(fixGroup.Id);
             var result   = Json(
                 new
             {
                 leader = new
                 {
                     id     = leader.Id,
                     name   = leader.Name,
                     number = leader.Number
                 },
                 members = members.Select(m => new
                 {
                     id     = m.Id,
                     name   = m.Name,
                     number = m.Number
                 })
             });
             return(result);
         }
     }
     catch (ArgumentException)
     {
         return(StatusCode(400, new { msg = "课程ID格式错误" }));
     }
 }
Example #3
0
        public IActionResult GetStudentListUnderClass(long classId, [FromQuery] string studentNumber, [FromQuery] string studentName)
        {
            try
            {
                if (studentNumber == null)
                {
                    studentNumber = "";
                }
                if (studentName == null)
                {
                    studentName = "";
                }
                IList <UserInfo> studentList = _userService.ListUserByClassId(classId, studentNumber, studentName);

                //找到学生所属小组
                FixGroup fixGroup = _fixGroupService.GetFixedGroupById(User.Id(), classId);
                if (fixGroup != null)
                {
                    IList <UserInfo> groupMember = _fixGroupService.ListFixGroupMemberByGroupId(fixGroup.Id);
                    foreach (UserInfo u in groupMember)
                    {
                        studentList.Remove(u);
                    }
                }

                List <UserVO> studentVO = new List <UserVO>();
                foreach (UserInfo u in studentList)
                {
                    studentVO.Add(u);
                }

                return(Json(studentVO));
            }
            catch (ClassNotFoundException) { return(NotFound(new { msg = "未找到该班级!" })); }
            catch (UserNotFoundException) { return(NotFound()); }
            catch (FixGroupNotFoundException) { return(NotFound()); }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
        public IActionResult GetUserClassGroupByClassId([FromRoute] long classId)
        {
            try
            {
                var userlogin = _userService.GetUserByUserId(User.Id());
                if (userlogin.Type != Shared.Models.Type.Student)
                {
                    return(StatusCode(403, new { msg = "权限不足" }));
                }

                var fixGroup = _fixGroupService.GetFixedGroupById(User.Id(), classId);
                var leader   = fixGroup.Leader ?? _userService.GetUserByUserId(fixGroup.LeaderId);
                var members  = _fixGroupService.ListFixGroupMemberByGroupId(fixGroup.Id);
                var result   = Json(
                    new
                {
                    leader = new
                    {
                        id     = leader.Id,
                        name   = leader.Name,
                        number = leader.Number
                    },
                    members = members.Select(m => new
                    {
                        id     = m.Id,
                        name   = m.Name,
                        number = m.Number
                    })
                });
                return(result);
            }
            catch (ArgumentException)
            {
                return(StatusCode(400, new { msg = "课程ID格式错误" }));
            }
        }
        /// <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();
        }