Example #1
0
        public async Task <IActionResult> CreateAuthorCollection(IEnumerable <AuthorCreationDto> authors)
        {
            if (!authors.Any())
            {
                return(NotFound());
            }

            var authorsEntity = _mapper.Map <IEnumerable <Author> >(authors);

            _courseLibraryRepository.AddAuthorRange(authorsEntity);
            await _courseLibraryRepository.SaveAsync();

            var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorsEntity);

            var idsToReturn = string.Join(",", authorCollectionToReturn.Select(c => c.Id));

            return(CreatedAtRoute(
                       "GetAuthorCollection",
                       new
            {
                authorIds = idsToReturn
                            //authorIds = authorsEntity.Select(c => c.Id)
                            //authorIds = from author in authorsEntity select author.Id
            },
                       authorCollectionToReturn));
        }