public IActionResult AddCourseStaff([FromBody] List <CourseStaffDto> courseStaffDto) { if (!ModelState.IsValid) { // return 422 return(new Helpers.UnprocessableEntityObjectResult(ModelState)); } try { // save var courseStaffFromRepo = _courseRepository.AddCourseStaff(courseStaffDto); var courseStaffToReturn = _mapper.Map <IEnumerable <CourseStaffDto> >(courseStaffFromRepo); return(Ok(courseStaffToReturn)); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }