Exemple #1
0
        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());
            }
        }
Exemple #2
0
 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());
 }
Exemple #3
0
 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格式错误" }));
     }
 }