Exemple #1
0
        public ActionResult <IEnumerable <AuthorDto> > CreateAuthorCollection(
            IEnumerable <AuthorForCreationDto> authorForCreationDtos)
        {
            var authorEntities = _mapper.Map <IEnumerable <Entities.Author> >(authorForCreationDtos);

            _courseLibraryRepository.AddAuthors(authorEntities);
            _courseLibraryRepository.Save();

            var authorsToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntities);
            var idsAsString     = string.Join(",", authorsToReturn.Select(a => a.Id));

            return(CreatedAtRoute(nameof(GetAuthorCollection),
                                  new { ids = idsAsString },
                                  authorsToReturn));
        }
Exemple #2
0
        public ActionResult <IEnumerable <AuhtorDTO> > CreateAuthorCollection(List <AuthorDTOW> authors)
        {
            var auhtorrs = _mapper.Map <List <Entities.Author> >(authors);

            //A bulk insert with BULK insert efcore extension
            _courseLibrary.AddAuthors(auhtorrs);
            //calling SvaeChnages not needed

            var createdAuthors = _mapper.Map <IEnumerable <AuhtorDTO> >(auhtorrs);

            return(Ok(new JsonResponse <AuhtorDTO>()
            {
                Success = true,
                Results = createdAuthors
            }));
        }
        public IActionResult Post(IEnumerable <AuthorCreationDto> authorCreationDtos)
        {
            var authors = _mapper.Map <IEnumerable <Author> >(authorCreationDtos);

            _repository.AddAuthors(authors);
            _repository.Save();

            var authorIds = _mapper.Map <List <AuthorDto> >(authors).Select(author => author.Id);
            var keys      = string.Join(',', authorIds);

            var result = CreatedAtRoute(
                "GetAuthorsByKeys",
                new
            {
                keys
            },
                keys);

            return(result);
        }