public ActionResult <AuthorDto> CreateAuthor(AuthorForCreation author) { var authorEntity = _mapper.Map <Author>(author); _coursesLibraryRepository.AddAuthor(authorEntity); _coursesLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn)); }
public async Task <ActionResult <AuthorForReturn> > CreateAuthor(AuthorForCreation author) { var authorToAdd = _mapper.Map <Author>(author); _repository.AddAuthor(authorToAdd); if (!await _repository.Save()) { return(BadRequest("Error Happens when saving in Data Base")); } var authorToReturn = _mapper.Map <AuthorForReturn>(authorToAdd); return(CreatedAtRoute("getAuthor", new { authorId = authorToAdd.Id }, authorToReturn)); }
public ActionResult <AuthorDto> AddAuthor(AuthorForCreation authorForCreation) { if (authorForCreation == null) { return(NotFound()); } var authorEntity = _mapper.Map <Author>(authorForCreation); _course.AddAuthor(authorEntity); _course.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new{ authorId = authorToReturn.Id }, authorToReturn)); }