public IActionResult DeleteTopic(long topicId) { // Authentication // 学生无法删除话题,返回403 if (User.Type() == Shared.Models.Type.Student) { return(StatusCode(403, new { msg = "学生无法删除话题!" })); } try { // Delete seminar from database // 怎么完成无法删除他人话题的权限判断??? _iTopicService.DeleteTopicByTopicId(topicId); // Success return(NoContent()); } //If topic not found, 返回404 catch (TopicNotFoundException) { return(NotFound(new { msg = "未找到该话题!" })); } //topicId 格式错误,返回400 catch (ArgumentException) { return(BadRequest(new { msg = "错误的ID格式!" })); } }
public IActionResult DeleteTopicById([FromRoute] long topicId) { if (User.Type() != Type.Teacher) { return(StatusCode(403, new { msg = "权限不足" })); } try { _topicService.DeleteTopicByTopicId(topicId); return(NoContent()); } catch (TopicNotFoundException) { return(StatusCode(404, new { msg = "话题不存在" })); } }
public IActionResult DeleteTopicById([FromRoute] long topicId) { try { _topicService.DeleteTopicByTopicId(topicId); return(NoContent()); } catch (UnauthorizedAccessException) { return(StatusCode(403, new { msg = "用户的权限不足" })); } catch (TopicNotFoundException) { return(StatusCode(404, new { msg = "未找到话题" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "错误的ID格式" })); } }
public IActionResult DeleteTopic(int topicId) { //IActionResult response = new IActionResult(HttpStatusCode.NoContent); //response.Content = new StringContent("成功", Encoding.UTF8); //return response; try { _topicService.DeleteTopicByTopicId(topicId); } catch (ClassNotFoundException) { return(StatusCode(404, new { msg = "未找到话题" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "错误的ID格式" })); } //catch (ArgumentException) //{ // return StatusCode(403, new { msg = "用户权限不足" }); //} return(NoContent()); }