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));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        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));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        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());
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        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));
        }
Esempio n. 15
0
        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));
        }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
        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));
        }
Esempio n. 20
0
        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));
        }
Esempio n. 21
0
        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));
        }
Esempio n. 24
0
        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));
        }
Esempio n. 25
0
        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));
        }
Esempio n. 27
0
        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));
        }
Esempio n. 30
0
        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));
        }