Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        public IActionResult DeleteStudentUnderClass(long classId, long studentId)
        {
            //学生无法为他人退课(URL中ID与自身ID不同)
            //if (studentId != User.Id()) return Forbid();

            try
            {
                _classService.DeleteCourseSelectionById(User.Id(), classId);

                //Success
                return(NoContent());
            }
            catch (UserNotFoundException) { return(NotFound("1")); }
            catch (ClassNotFoundException) { return(NotFound("2")); }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
        /// <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();
        }
Ejemplo n.º 4
0
 public IActionResult DeselectClass([FromRoute] long classId, [FromRoute] long studentId)
 {
     try
     {
         var user = _userService.GetUserByUserId(User.Id());
         if (user.Type == Shared.Models.Type.Student)
         {
             _classService.DeleteCourseSelectionById(studentId, classId);
             return(NoContent());
         }
         else
         {
             return(StatusCode(403, new { msg = "权限不足" }));
         }
     }
     catch (ArgumentException)
     {
         return(StatusCode(400, new { msg = "ID格式错误" }));
     }
 }
Ejemplo n.º 5
0
 public IActionResult DeleteClass(int classId, int userId, string studentId)
 {
     //IActionResult response = new IActionResult(HttpStatusCode.NoContent);
     //response.Content = new StringContent("成功", Encoding.UTF8);
     //return response;
     try
     {
         _classService.DeleteCourseSelectionById(classId, userId);
     }
     catch (ClassNotFoundException)
     {
         return(StatusCode(404, new { msg = "未找到班级" }));
     }
     catch (ArgumentException)
     {
         return(StatusCode(400, new { msg = "错误的ID格式" }));
     }
     //catch (CourseAlreadyExistsException)
     //{
     //    return StatusCode(409, new { msg = "选过同个课程" });
     //}
     return(NoContent());
 }