public IActionResult DeleteClass(long classId) { // Authentication // 学生无法删除班级,返回403 if (User.Type() == Shared.Models.Type.Student) { return(Forbid("1")); } try { //无法删除他人班级 ClassInfo classInfo = _classService.GetClassByClassId(classId); if (classInfo.Course.Teacher.Id != User.Id()) { return(Forbid("2")); } _classService.DeleteClassByClassId(classId); //Success return(NoContent()); } //If not found, 返回404 catch (ClassNotFoundException) { return(NotFound(new { msg = "未找到该班级!" })); } //classId格式错误,返回400 catch (ArgumentException) { return(BadRequest()); } }
public IActionResult DeleteClass(int classId) { try { _classService.DeleteClassByClassId(classId); } catch (ClassNotFoundException) { return(StatusCode(404, new { msg = "未找到班级" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "错误的ID格式" })); } return(NoContent()); }
public IActionResult DeleteClassById([FromRoute] long classId) { try { var user = _userService.GetUserByUserId(User.Id()); if (user.Type != Shared.Models.Type.Teacher) { return(StatusCode(403, new { msg = "权限不足" })); } _classService.DeleteClassByClassId(classId); return(NoContent()); } catch (ClassNotFoundException) { return(StatusCode(404, new { msg = "未找到班级" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "班级ID格式错误" })); } }