Example #1
0
        public async Task <IActionResult> AddClassroom([FromBody] CreateClassroomDto createClassroomDto)
        {
            if (createClassroomDto == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var cls = await _classroomService.GetClassroomsByClassName(createClassroomDto.Name);

            var cls1 = await _classroomService.GetClassroomsByClassNum(createClassroomDto.ClassRoomNum);

            if (cls.Count > 0 || cls1.Count > 0)
            {
                return(BadRequest("教室名称或教室编号已存在"));
            }
            var res = _mapper.Map <Classroom>(createClassroomDto);

            _classroomService.AddT(res);
            if (!await _classroomService.Save())
            {
                return(StatusCode(500, "添加教室信息时出错"));
            }
            return(Created("", createClassroomDto));
        }
        public async Task <IActionResult> AddCourseClassroom([FromBody] CreateCourseClassroomDto create)
        {
            if (create == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var crs = await _courseService.GetCourseByCourseNameDetail(create.CourseName);

            var cls = await _classroomService.GetClassroomsByClassName(create.ClassroomName);

            if (crs.Count == 0 || cls.Count == 0)
            {
                return(BadRequest("课程名称或者教室名称不存在"));
            }
            CourseClassroom classroom = new CourseClassroom()
            {
                Course    = crs.FirstOrDefault(),
                Classroom = cls.FirstOrDefault()
            };

            _courseClassroomService.AddT(classroom);
            if (!await _courseClassroomService.Save())
            {
                return(StatusCode(500, "添加数据时错误"));
            }
            return(Created("", create));
        }