Exemple #1
0
 [HttpPut("/seminar/{seminarId:long}")]//测试成功
 public IActionResult UpdateSeminarById([FromRoute] long seminarId, [FromBody] Seminar updated)
 {
     try
     {
         _service.UpdateSeminarBySeminarId(seminarId, updated);
         return(NoContent());
     }
     catch (SeminarNotFoundException)
     {
         return(StatusCode(404, new { msg = "讨论课不存在!" }));
     }
     catch (TopicNotFoundException)
     {
         return(StatusCode(404, new { msg = "话题不存在!" }));
     }
 }
        public IActionResult PutSeminar(long seminarId, [FromBody] dynamic json)
        {
            // Authentication
            // 学生无法修改讨论课,返回403
            if (User.Type() == Shared.Models.Type.Student)
            {
                return(StatusCode(403, new { msg = "学生无法修改讨论课!" }));
            }

            try
            {
                string startTime = json.StartTime;
                string endTime   = json.EndTime;
                // Get information from json
                Seminar editedSeminar = new Seminar {
                    Id = seminarId, Name = json.Name, Description = json.Description, StartTime = Convert.ToDateTime(startTime), EndTime = Convert.ToDateTime(endTime)
                };
                // 这里groupingMethod返回的是fixed还是固定分组???
                if (json.GroupingMethod == "fixed" || json.GroupingMethod == "固定分组")
                {
                    editedSeminar.IsFixed = true;
                }
                else if (json.GroupingMethod == "random" || json.GroupingMethod == "随机分组")
                {
                    editedSeminar.IsFixed = false;
                }

                //Change information in database
                _iSeminarService.UpdateSeminarBySeminarId(seminarId, editedSeminar);

                //Success
                return(NoContent());
            }
            //If seminar not found, 返回404
            catch (SeminarNotFoundException)
            {
                return(NotFound(new { msg = "未找到该讨论课!" }));
            }
            //seminarId 格式错误,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }
 public IActionResult UpdateSeminarById([FromRoute] long seminarId, [FromBody] Seminar updated)
 {
     if (User.Type() != Type.Teacher)
     {
         return(StatusCode(403, new { msg = "权限不足" }));
     }
     try
     {
         _seminarService.UpdateSeminarBySeminarId(seminarId, updated);
         return(NoContent());
     }
     catch (SeminarNotFoundException)
     {
         return(StatusCode(404, new { msg = "讨论课不存在" }));
     }
     catch (ArgumentException)
     {
         return(StatusCode(400, new { msg = "讨论课ID输入格式有误" }));
     }
 }
Exemple #4
0
 public IActionResult PutSeminarById([FromRoute] int seminarId, [FromBody] Seminar seminar)
 {
     //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.NotFound);
     //response3.Content = new StringContent("未找到讨论课", Encoding.UTF8);
     //return response;
     try
     {
         _seminarService.UpdateSeminarBySeminarId(seminarId, seminar);
     }
     catch (SeminarNotFoundException)
     {
         return(StatusCode(404, new { msg = "未找到讨论课" }));
     }
     catch (ArgumentException)
     {
         return(StatusCode(400, new { msg = "错误的ID格式" }));
     }
     return(NoContent());
 }