public async Task <IActionResult> UpdateMajor(int id, [FromBody] ModifyMajorDto modifyMajor) { if (modifyMajor == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var mj = await _majorService.GetTById(id); if (mj == null) { return(NotFound()); } if (mj.MajorName != modifyMajor.MajorName) { if (await _majorService.MjNameIsExist(modifyMajor.MajorName)) { return(BadRequest("专业名称已存在")); } } if (mj.MajorNum != modifyMajor.MajorNum) { if (await _majorService.MjNumIsExist(modifyMajor.MajorNum)) { return(BadRequest("专业编号已存在")); } } mj.MajorName = modifyMajor.MajorName; mj.MajorNum = modifyMajor.MajorNum; _mapper.Map(mj, mj); if (!await _majorService.Save()) { return(StatusCode(500, "更新专业信息时出错")); } return(Created("", modifyMajor)); }