public async Task <IActionResult> AddMajor([FromBody] CreateMajorDto createMajorDto) { if (createMajorDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _majorService.IsExist(createMajorDto.MajorName, createMajorDto.MajorNum)) { return(BadRequest("专业名称或编号已存在")); } var res = _mapper.Map <Major>(createMajorDto); _majorService.AddT(res); if (!await _majorService.Save()) { return(StatusCode(500, "添加专业时出现错误")); } return(Created("", createMajorDto)); }