public async Task InsertAsync_ShouldInsertOrchestralPiece()
        {
            var createDto = new OrchestralPieceCreateDto
            {
                Title    = "ABBA GOLD",
                Composer = "Ron Sebregets",
                Tempo    = 120,
                SongLink = "https://www.youtube.com/watch?v=3P9NC4dB89Y",
                OrchestralBriefcasesLinks =
                {
                    new OrchestralBriefcaseOrchestralPieceDto
                    {
                        NumberInOrchestralBriefcase = 1,
                        OrchestralBriefcaseId       = 1
                    }
                }
            };

            using (var context = new ApplicationDbContext(DbContextOptions))
            {
                var orchestralPieceService = new OrchestralPiecesService(context, _mapper);
                await orchestralPieceService.CreateAsync(createDto);
            }

            using (var context = new ApplicationDbContext(DbContextOptions))
            {
                var orchestralPiece = context.OrchestralPieces.Find(1);

                Assert.Equal(createDto.Title, orchestralPiece.Title);
                Assert.Equal(createDto.Composer, orchestralPiece.Composer);
                Assert.Equal(createDto.Tempo, orchestralPiece.Tempo);
                Assert.Equal(createDto.SongLink, orchestralPiece.SongLink);
            }
        }
        public async Task <ActionResult <int> > Create(OrchestralPieceCreateDto createDto)
        {
            if (!ModelState.IsValid)
            {
                return(ValidationProblem(ModelState));
            }

            int id = await _orchestralPieceService.CreateAsync(createDto);

            return(CreatedAtAction(nameof(GetById), new { id }, id));
        }
        public async Task <int> CreateAsync(OrchestralPieceCreateDto createDto)
        {
            //foreach (var link in createDto.OrchestralBriefcasesLinks)
            //{
            //    bool doesOrchestralBriefcaseExist = await _dbContext.OrchestralBriefcases
            //        .AnyAsync(orchBriefcase => orchBriefcase.Id == link.OrchestralBriefcaseId)
            //        .ConfigureAwait(false);

            //    if (doesOrchestralBriefcaseExist is false)
            //    {
            //        throw new NotFoundException(nameof(OrchestralBriefcase), )
            //    }
            //}
            var orchestralPiece = new OrchestralPiece
            {
                Title    = createDto.Title,
                Composer = createDto.Composer,
                Tempo    = createDto.Tempo,
                SongLink = createDto.SongLink
            };

            foreach (var link in createDto.OrchestralBriefcasesLinks)
            {
                orchestralPiece.OrchestralBriefcaseLinks.Add(
                    new OrchestralBriefcaseOrchestralPiece
                {
                    OrchestralPiece             = orchestralPiece,
                    OrchestralBriefcaseId       = link.OrchestralBriefcaseId,
                    NumberInOrchestralBriefcase = link.NumberInOrchestralBriefcase
                });
            }

            _dbContext.OrchestralPieces.Add(orchestralPiece);
            await _dbContext
            .SaveChangesAsync()
            .ConfigureAwait(false);

            return(orchestralPiece.Id);
        }
 public Task CreateOrchestralPiece(OrchestralPieceCreateDto createdto)
 {
     return(_httpClient
            .PostAsJsonAsync(_baseEndpoint, createdto));
 }