/// <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(); }
public IActionResult RemoveMemberIntoClassGroup(long classId, [FromBody] dynamic json) { try { //Authentication 权限不足(不是该小组的成员/组长) FixGroup fixGroup = _fixGroupService.GetFixedGroupById(User.Id(), classId); if (fixGroup.LeaderId != User.Id() || json.StudentId == User.Id()) { return(Forbid()); } long studentId = json.StudentId; // Remove student from this classgroup database _fixGroupService.DeleteFixGroupUserById(fixGroup.Id, studentId); // Success return(NoContent()); } catch (FixGroupNotFoundException) { return(NotFound("1")); } catch (UserNotFoundException) { return(NotFound("2")); } catch (ArgumentException) { return(BadRequest()); } }
public IActionResult RemoveGroupMemberByClassId([FromRoute] long classId, [FromBody] UserInfo student) { try { var group = _fixGroupService.GetFixedGroupById(User.Id(), classId); _fixGroupService.DeleteFixGroupUserById(group.Id, student.Id); return(NoContent()); } catch (ClassNotFoundException) { return(StatusCode(404, new { msg = "不存在当前班级" })); } 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(); }
public IActionResult RemoveGroupMember(long groupId, [FromBody] dynamic json) { try//注意看service有没有判断存不存在该学生 { long userId = json.id; _iFixGroupService.DeleteFixGroupUserById(groupId, userId); } catch (UserNotFoundException) { return(NotFound()); } catch (GroupNotFoundException) { return(NotFound()); } catch (ArgumentException) { return(BadRequest()); } return(NoContent()); }