public async Task <AuthorDTO> CreateAuthor(AuthorForCreationDTO author) { var authorEntity = mapper.Map <Author>(author); await authorRepository.Create(authorEntity); return(createLinksStrategy.CreateLinksForAuthorResource(mapper.Map <AuthorDTO>(authorEntity))); }
public async Task <IActionResult> Post([FromBody] AuthorForCreationDTO author) { if (author == null) { return(BadRequest()); } var authorToReturn = await createAuthorStrategy.CreateAuthor(author); return(Created("GetAuthor", authorToReturn)); }
public ActionResult <AuthorDto> Create(AuthorForCreationDTO creationDTO) { var entity = _mapper.Map <Author>(creationDTO); _courseLibrary.AddAuthor(entity); _courseLibrary.Save(); var entityToReturn = _mapper.Map <AuthorDto>(entity); return(CreatedAtRoute("GetAuthor", new { Id = entityToReturn.Id }, entityToReturn)); }
public ActionResult <AuthorDTO> CreateAuthor(AuthorForCreationDTO author) { var authorEntity = _mapper.Map <Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDTO>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorID = authorToReturn.Id }, authorToReturn)); }
public ActionResult <AuthorDTO> CreateAuthor(AuthorForCreationDTO author) { var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); // once we get the authorId via Save(), we can return the author var authorToReturn = _mapper.Map <AuthorDTO>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn)); }
public ActionResult <AuthorDTO> CreateAuthor(AuthorForCreationDTO authorForCreationDTO) { var authorEntity = _mapper.Map <Author>(authorForCreationDTO); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToRetrun = _mapper.Map <AuthorDTO>(authorEntity); // RouteName will be that, which is defined in [HttpPost, Name="..Name.."] return(CreatedAtRoute("GetAuthor", new { authorId = authorToRetrun.Id }, authorToRetrun)); }
public ActionResult <AuthorDTO> CreateAuthor(AuthorForCreationDTO author) { if (author == null) { return(BadRequest()); } var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorReturned = _mapper.Map <AuthorDTO>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorReturned.Id }, authorReturned)); }
public async Task <ActionResult> Post([FromBody] AuthorForCreationDTO authorForCreationDTO) { if (authorForCreationDTO == null) { _logger.LogError("authorForCreationDTO object send from client is null"); return(BadRequest("authorForCreationDTO object is null")); } var author = _mapper.Map <Author>(authorForCreationDTO); _repositoryManager.Author.CreateAuthor(author); await _repositoryManager.SaveAsync(); var authorToReturn = _mapper.Map <AuthorReturnCreateDTO>(author); return(CreatedAtRoute("AuthorById", new { id = authorToReturn.AuthorId }, authorToReturn)); }
public ActionResult <AuthorDTO> CreateAuthor(AuthorForCreationDTO author) { // null check is not needed for author // .net core does it for us automatically var authorEntity = _mapper.Map <Author>(author); _clRepo.AddAuthor(authorEntity); _clRepo.Save(); // AddAuthor method adds an Id value to the passed value. var authorToReturn = _mapper.Map <AuthorDTO>(authorEntity); return(CreatedAtRoute( "GetAuthor", new { authorId = authorToReturn.Id }, // route paramters authorToReturn )); }
public IActionResult CreateAuthor([FromBody] AuthorForCreationDTO author) { if (author == null) { return(BadRequest()); } var authorEntity = AutoMapper.Mapper.Map <Author>(author); libRepo.AddAuthor(authorEntity); if (!libRepo.Save()) { throw new Exception("Creation of author failed on save"); } var authorDto = AutoMapper.Mapper.Map <AuthorDTO>(authorEntity); return(CreatedAtRoute("GetAuthor", new { id = authorDto.Id }, authorDto)); }