public async Task <ActionResult <CourseDto> > CreateCourseForAuthor(Guid authorId, [FromBody] CourseCreateDto course) { if (!await _authorRepository.AuthorExistsAsync(authorId)) { return(NotFound()); } try { var courseEntity = _mapper.Map <Course>(course); await _courseRepository.AddCourseAsync(authorId, courseEntity); var courseToReturn = _mapper.Map <CourseDto>(courseEntity); // Return - successful post - 201 - CreatedAtRoute() - 201 SC and a location header with // URI for newly created Course return(CreatedAtRoute("GetCourseForAuthor", new { authorId = authorId, courseId = courseEntity.Id }, courseToReturn)); } catch (Exception e) { return(BadRequest()); } }