Example #1
0
        public async Task <IActionResult> CreateAlbum(AlbumForCreationDTO albumForCreationDto)
        {
            var newAlbum = _mapper.Map <Album>(albumForCreationDto);

            _albumRepo.AddAlbum(newAlbum);

            await _albumRepo.SaveChangesAsync();

            await _albumRepo.GetAlbumAsync(newAlbum.Id);

            return(CreatedAtRoute("GetAlbum", new { id = newAlbum.Id }, newAlbum));
        }
Example #2
0
        public async Task <IActionResult> CreateAlbumCollection(IEnumerable <AlbumForCreationDTO> albumCollectionDto)
        {
            var newAlbumCollection = _mapper.Map <IEnumerable <Album> >(albumCollectionDto);

            foreach (var albumItem in newAlbumCollection)
            {
                _albumRepo.AddAlbum(albumItem);
            }

            await _albumRepo.SaveChangesAsync();

            var createdAlbumCollectiton = await _albumRepo.GetAlbumsAsync(newAlbumCollection.Select(a => a.Id));

            var AlbumIds = string.Join(",", createdAlbumCollectiton.Select(a => a.Id));

            return(CreatedAtRoute("GetAlbumCollection", new { AlbumIds }, createdAlbumCollectiton));
        }