Exemple #1
0
        public IActionResult CreateSeminarByCourseId([FromRoute] long courseId, [FromBody] Seminar newSeminar)
        {
            var userlogin = _userService.GetUserByUserId(User.Id());

            if (userlogin.Type == Type.Teacher)
            {
                var seminarId = _seminarService.InsertSeminarByCourseId(courseId, newSeminar);
                return(Created($"/seminar/{seminarId}", new { id = seminarId }));
            }
            return(StatusCode(403, new { msg = "权限不足" }));
        }
        public IActionResult PostNewSeminar(long courseId, [FromBody] dynamic json)
        {
            // Authentication
            // 学生无法创建讨论课,返回403
            if (User.Type() == Shared.Models.Type.Student)
            {
                return(StatusCode(403, new { msg = "学生无法创建讨论课!" }));
            }

            try
            {
                //Convert.ToDateTime(json.StartTime);
                string startTime = json.StartTime;
                startTime = startTime.Replace("-", "/");
                string endTime = json.EndTime;
                endTime = endTime.Replace("-", "/");

                //Get information from json
                // 所以获得的组内限制和组内人数上限存在哪个实体里???
                Seminar newSeminar;
                if (json.GroupingMethod == "fixed")
                {
                    newSeminar = new Seminar {
                        Name = json.Name, Description = json.Description, IsFixed = true, StartTime = Convert.ToDateTime(startTime), EndTime = Convert.ToDateTime(endTime)
                    }
                }
                ;
                else
                {
                    newSeminar = new Seminar {
                        Name = json.Name, Description = json.Description, IsFixed = false, StartTime = Convert.ToDateTime(startTime), EndTime = Convert.ToDateTime(endTime)
                    }
                };

                // Store seminar information in server and generate a id for this new seminar
                long newSeminarId = _iSeminarService.InsertSeminarByCourseId(courseId, newSeminar);

                // Return seminar id
                string uri = "/seminar/" + newSeminarId;
                return(Created(uri, newSeminar));
            }
            // 未找到课程,返回404
            catch (CourseNotFoundException)
            {
                return(NotFound(new { msg = "未找到该课程!" }));
            }
            // 错误的ID格式,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }
Exemple #3
0
        public IActionResult PostSeminar([FromRoute] long courseId, Seminar seminar)
        {
            try
            {
                var seminars = _seminarService.InsertSeminarByCourseId(courseId, seminar);
                return(Json(seminars));
            }
            catch (InvalidOperationException)
            {
                return(StatusCode(403, new { msg = "学生无法创建" }));
            }

            //JsonResult result = new JsonResult();
            //var Class = new { id = 32 };
            //result.Data = Class;
            //result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            //return result;
        }