Example #1
0
        public async Task <IActionResult> AddAchievement([FromBody] CreateAchievementDto createAchievementDto)
        {
            var stu = await _studentService.GetStudentDetailByStuName(createAchievementDto.StuName);

            var cs = await _courseService.GetCourseByCourseNameDetail(createAchievementDto.CourseName);

            if (stu.Count == 0 || cs.Count == 0)
            {
                return(BadRequest("学生或者课程不存在"));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Achievement achievement = new Achievement();

            achievement.Student = stu.FirstOrDefault();
            achievement.Course  = cs.FirstOrDefault();
            achievement.Score   = createAchievementDto.Score;
            _achievementService.AddT(achievement);
            if (!await _achievementService.Save())
            {
                return(StatusCode(500, "添加信息时出错"));
            }
            return(Created("", ""));
        }