public IActionResult DeleteSeminarById([FromRoute] int seminarId) { //IActionResult response = new IActionResult(HttpStatusCode.NoContent); //response.Content = new StringContent("成功", Encoding.UTF8); //IActionResult response2 = new IActionResult(HttpStatusCode.BadRequest); //response2.Content = new StringContent("错误的ID格式", Encoding.UTF8); //IActionResult response3 = new IActionResult(HttpStatusCode.Forbidden); //response3.Content = new StringContent("权限不足", Encoding.UTF8); //IActionResult response4 = new IActionResult(HttpStatusCode.NotFound); //response3.Content = new StringContent("未找到讨论课", Encoding.UTF8); //return response; try { _seminarService.DeleteSeminarBySeminarId(seminarId); } catch (SeminarNotFoundException) { return(StatusCode(404, new { msg = "未找到讨论课" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "错误的ID格式" })); } return(NoContent()); }
public IActionResult DeleteSeminar(long seminarId) { // Authentication // 学生无法删除讨论课,返回403 if (User.Type() == Shared.Models.Type.Student) { return(StatusCode(403, new { msg = "学生无法删除讨论课!" })); } try { // Delete seminar from database // 怎么完成无法删除他人讨论课的权限判断??? _iSeminarService.DeleteSeminarBySeminarId(seminarId); // Success return(NoContent()); } //If seminar not found, 返回404 catch (SeminarNotFoundException) { return(NotFound(new { msg = "未找到该讨论课!" })); } //seminarId 格式错误,返回400 catch (ArgumentException) { return(BadRequest(new { msg = "错误的ID格式!" })); } }
[HttpDelete("/seminar/{seminarId:long}")]//测试成功 public IActionResult DeleteSeminarById([FromRoute] long seminarId) { try { _service.DeleteSeminarBySeminarId(seminarId); return(NoContent()); } catch (SeminarNotFoundException) { return(StatusCode(404, new { msg = "讨论课不存在!" })); } }
public IActionResult DeleteSeminarById([FromRoute] long seminarId) { if (User.Type() != Type.Teacher) { return(StatusCode(403, new { msg = "权限不足" })); } try { _seminarService.DeleteSeminarBySeminarId(seminarId); return(NoContent()); } catch (SeminarNotFoundException) { return(StatusCode(404, new { msg = "讨论课不存在" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "讨论课ID输入格式有误" })); } }