public AuthorDto AddAuthor(NewAuthorDto author) { var authorEntity = _mapper.Map <Author>(author); _repo.AddAuthor(authorEntity); _repo.Save(); return(_mapper.Map <AuthorDto>(authorEntity)); }
public ActionResult <AuthorDto> CreateAuthor(NewAuthorDto author) { var newAuthor = _manager.AddAuthor(author); var linkedResourceToReturn = newAuthor.ShapeData(null) as IDictionary <string, object>; var links = CreateLinksForAuthor(newAuthor.Id, null); linkedResourceToReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourceToReturn["Id"] }, linkedResourceToReturn)); }
public IActionResult CreateAuthor([FromBody] NewAuthorDto author) { if (author == null) { return(BadRequest()); } var authorEntity = Mapper.Map <Data.Author>(author); this.repository.AddAuthor(authorEntity); if (!repository.Save()) { throw new Exception("Creating an author failed on save"); } var newAuthor = Mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { id = newAuthor.Id }, newAuthor)); }