public async Task UpdateAsync(OrchestralPieceUpdateDto updateDto) { var entity = await _dbContext.OrchestralPieces .Include(entity => entity.OrchestralBriefcaseLinks) .FirstOrDefaultAsync(entity => entity.Id == updateDto.Id); if (entity is null) { throw new NotFoundException(nameof(OrchestralPiece), updateDto.Id); } entity.Title = updateDto.Title; entity.Composer = updateDto.Composer; entity.Tempo = updateDto.Tempo; entity.SongLink = updateDto.SongLink; foreach (var link in updateDto.OrchestralBriefcasesLinks) { entity.OrchestralBriefcaseLinks.Add( new OrchestralBriefcaseOrchestralPiece { OrchestralPieceId = entity.Id, OrchestralBriefcaseId = link.OrchestralBriefcaseId, NumberInOrchestralBriefcase = link.NumberInOrchestralBriefcase }); } await _dbContext .SaveChangesAsync() .ConfigureAwait(false); }
public Task UpdateOrchestralPiece(int id, OrchestralPieceUpdateDto updateDto) { string endpoint = $"{_baseEndpoint}/{id}"; return(_httpClient .PutAsJsonAsync(endpoint, updateDto)); }
public async Task <IActionResult> Update(int id, OrchestralPieceUpdateDto updateDto) { if (id != updateDto.Id) { return(BadRequest()); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } await _orchestralPieceService.UpdateAsync(updateDto); return(Ok()); }