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(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(CreateAuthorDto createAuthorDto) { var newAuthor = _mapper.Map <Author>(createAuthorDto); _courseLibraryRepository.AddAuthor(newAuthor); _courseLibraryRepository.Save(); var authorDto = _mapper.Map <AuthorDto>(newAuthor); return(CreatedAtRoute("GetAuthor", new { authorId = authorDto.Id }, authorDto)); }
public ActionResult <AuthorDto> CreateAuthors(AuthorForCreationDto authorForCreation) { var authorEntity = _mapper.Map <Author>(authorForCreation); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var linkedResourceToReturn = _mapper.Map <AuthorDto>(authorEntity).ShapeData(null) as IDictionary <string, object>; var links = CreateLinksForAuthor(authorEntity.Id, null); linkedResourceToReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourceToReturn["Id"] }, linkedResourceToReturn)); }
public IActionResult CreateAuthorWithDateOfDeath(AuthorForCreationWithDateOfDeathDto authorToAdd) { Author authorEntity = _mapper.Map <Author>(authorToAdd); _repository.AddAuthor(authorEntity); _repository.Save(); var linkResourceToReturn = _mapper.Map <AuthorDto>(authorEntity).ShapeData() as IDictionary <string, object>; var links = CreateLinksForAuthor(authorEntity.Id); linkResourceToReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = authorEntity.Id }, linkResourceToReturn)); }
public IActionResult CreateAuthor([FromBody] CreateAuthorDto createAuthorDto) { var author = mapper.Map <Author>(createAuthorDto); courseRepository.AddAuthor(author); courseRepository.Save(); return(CreatedAtRoute("GetAuthor", new { authorId = author.Id }, author)); }
public IActionResult CreateAuthorWithDateofDeath(AuthorForCreationWithDateOfDeathDto author) { var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); var links = CreateLinksForAuthor(authorToReturn.Id, null); var linkedResourcetoReturn = authorToReturn.ShapeData(null) as IDictionary <string, object>; linkedResourcetoReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourcetoReturn["Id"] }, linkedResourcetoReturn)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorForCreationDto authorForCreation) { var author = mapper.Map <Author>(authorForCreation); repository.AddAuthor(author); repository.Save(); var authorResult = mapper.Map <AuthorDto>(author); return(CreatedAtRoute("GetAuthor", new { authorId = author.Id }, authorResult)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorForCreationDto author) { var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); var result = _mapper.Map <AuthorDto>(authorToReturn) .ShapeData(null) as IDictionary <string, object>; var links = CreateLinksForAuthor(authorToReturn.Id, null); result.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, result)); }
public IActionResult CreateAuthor(CreateAuthorDTO authorRequest) { var author = _mapper.Map <Author>(authorRequest); _courseLibrary.AddAuthor(author); _courseLibrary.Save(); var authorToReturn = _mapper.Map <AuthorDTO>(author); return(CreatedAtRoute("GetAuthor", new { authorId = author.Id }, authorToReturn)); }
public ActionResult <AuthorDto> CreateAuthor([FromBody] AuthorCreationDto author) { var authorEntity = _mapper.Map <Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorDto = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute(nameof(GetAuthor), new { authorId = authorDto.Id }, authorDto)); }
public ActionResult <IEnumerable <AuthorDto> > CreateAuthorCollection(IEnumerable <AuthorCreationDto> authorCollection) { var authorEntities = _mapper.Map <IEnumerable <Entities.Author> >(authorCollection); foreach (var author in authorEntities) { _courseLibraryRepository.AddAuthor(author); } _courseLibraryRepository.Save(); return(Ok()); }
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> CreateAuthorWithDateOfDeath(AuthorForCreationWithDateOfDeathDto author) { if (author == null) { return(BadRequest()); } var authorEntity = _mapper.Map <Entities.Author>(author); _courselibraryRepository.AddAuthor(authorEntity); _courselibraryRepository.Save(); var authorDto = _mapper.Map <AuthorDto>(authorEntity); var links = CreateLinkForAuthor(authorDto.Id, null); var linkedResourceForReturn = authorDto.ShapeData(null) as IDictionary <string, object>; linkedResourceForReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = linkedResourceForReturn["Id"] }, linkedResourceForReturn)); }
public IActionResult AddAuthor([FromBody] AuthorForCreationDto authorForCreation) { var author = _mapper.Map <Author>(authorForCreation); _courseLibraryRepository.AddAuthor(author); _courseLibraryRepository.Save(); var result = _mapper.Map <AuthorDto>(author); return(CreatedAtRoute("GetAuthor", new { authorId = author.Id }, result)); }
public ActionResult <AuthorGetDto> CreateAuthor(AuthorCreateDto author) { var authorEntity = _mapper.Map <Author>(author); _repo.AddAuthor(authorEntity); _repo.Save(); var authorToReturn = _mapper.Map <AuthorGetDto>(authorEntity); return(CreatedAtAction(nameof(GetAuthors), 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) { // Checking if the input parameter is null is done by the [ApiController] attribute. var authorEntity = _mapper.Map <Entities.Author>(author); // Add it to the repository _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity);// AuthorEntity to AuthorDto because we need to return an object of type AuthorDto. // CreatedAtRoute() helper method will allow to send a 201 Created Response with a location header for a successful post return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn)); }
public ActionResult <AuthorDto> Post(AuthorForCreationDto author) { var newAuthor = _mapper.Map <Author>(author); _repository.AddAuthor(newAuthor); _repository.Save(); var authorDto = _mapper.Map <AuthorDto>(newAuthor); var shapedAuthor = _dataShapingService.ShapeData(authorDto) as IDictionary <string, object>; var links = CreateAuthorLinks(authorDto.Id, null); shapedAuthor.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = authorDto.Id }, shapedAuthor)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorInputDto authoeInput) { var authorEntity = _mapper.Map <Entities.Author>(authoeInput); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorOutput = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthor", new { authorId = authorOutput.Id }, authorOutput)); }
public IActionResult CreateAuthor(AuthorForCreationDto authorForCreationDto) { var authorForCreation = _mapper.Map <Author>(authorForCreationDto); _courseLibraryRepository.AddAuthor(authorForCreation); _courseLibraryRepository.Save(); var createdAuthor = _mapper.Map <AuthorDto>(authorForCreation); var links = GetLinksForAuthor(createdAuthor.Id); var linkedResourceToReturn = createdAuthor.ShapeData() as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(CreatedAtRoute("GetAuthor", new { authorId = createdAuthor.Id }, linkedResourceToReturn)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorsForCreationDto author) { // Added to the DbContext var authorEntity = _mapper.Map <Entities.Author>(author); // Added to the Repository _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); return(CreatedAtRoute("GetAuthors", new { authorId = authorToReturn.Id }, authorToReturn)); }
public ActionResult <AuthorDto> CreateAuthor(AuthorForCreationDto author) { var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); // return othe route method, in this case GetAuthor return(CreatedAtRoute("GetAuthor", new { authorId = authorEntity.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 <IEnumerable <AuthorDto> > CreateAuthorCollection(IEnumerable <AuthorForCreationDto> authorCollection) { var authorEntities = _mapper.Map <IEnumerable <Entities.Author> >(authorCollection); foreach (var author in authorEntities) { _courseLibraryRepository.AddAuthor(author); } _courseLibraryRepository.Save(); var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntities); var idsAsString = string.Join(",", authorCollectionToReturn.Select(a => a.Id)); return(CreatedAtRoute("GetAuthorCollection", new { ids = idsAsString }, authorCollectionToReturn)); }
public IActionResult CreateAuthor(AuthorForCreationDto authorForCreation) { var createdEntity = mMapper.Map <Author>(authorForCreation); mRepository.AddAuthor(createdEntity); mRepository.SaveChangesAsync(); var createdDtoToReturn = mMapper.Map <AuthorDto>(createdEntity); var linkedResource = createdDtoToReturn.ShapeData(null) as IDictionary <string, object>; linkedResource.Add("links", CreateLinksForAuthor(createdEntity.Id, null)); return(CreatedAtRoute("GetAuthor", new { authorId = linkedResource["Id"] }, linkedResource)); }
public IActionResult CreateAuthor( [FromBody] AuthorForCreationDto author, [FromHeader(Name = "Accept")] string mediaType) { var authorEntity = _mapper.Map <Entities.Author>(author); _courseLibraryRepository.AddAuthor(authorEntity); _courseLibraryRepository.Save(); var authorToReturn = _mapper.Map <AuthorDto>(authorEntity); var links = CreateLinksForAuthor(authorToReturn.Id, string.Empty); var linkedResourceToReturn = authorToReturn.ShapeData(string.Empty) as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(CreatedAtRoute( routeName: "GetAuthor", routeValues: new { authorId = linkedResourceToReturn["Id"] }, value: linkedResourceToReturn)); }
public ActionResult <IEnumerable <AuthorDto> > Post(IEnumerable <AuthorForCreationDto> authors) { var newAuthors = _mapper.Map <IEnumerable <Author> >(authors); foreach (var newAuthor in newAuthors) { _repository.AddAuthor(newAuthor); } _repository.Save(); var newAuthorIds = string.Join(',', newAuthors.Select(a => a.Id.ToString()).ToArray()); var authorsToReturn = _mapper.Map <IEnumerable <AuthorDto> >(newAuthors); return(CreatedAtRoute("GetAuthorCollections", new { authorIds = newAuthorIds }, authorsToReturn)); }
public ActionResult <IEnumerable <AuthorDto> > CreateAuthorCollection(IEnumerable <AuthorForCreateDto> authors) { var entities = mapper.Map <IEnumerable <Author> >(authors); foreach (var elem in entities) { courseLibraryRepository.AddAuthor(elem); } courseLibraryRepository.Save(); var authorCollectionToReturn = mapper.Map <IEnumerable <AuthorDto> >(entities); var ids = string.Join(",", authorCollectionToReturn.Select(x => x.Id)); return(CreatedAtRoute("GetAuthorsCollection", new { ids = ids }, authorCollectionToReturn)); }