public async Task <ActionResult <SongAddDTO> > AddSong(SongAddDTO song) { try { return(new OkObjectResult(await _labelService.AddSong(song))); } catch (Exception ex) { throw ex; } }
public async Task <SongAddDTO> AddSong(SongAddDTO song) { try { // voor DTO Song newSong = _mapper.Map <Song>(song); newSong.SongId = Guid.NewGuid(); foreach (var artistId in song.ArtistIds) { Artist artist = await GetArtistByArtistId(artistId); if (artist != null) { await _songRepository.AddSongArtist(new SongArtist() { SongArtistId = Guid.NewGuid(), SongId = newSong.SongId, ArtistId = artistId, }); } } Recordlabel recordlabel = await GetRecordlabelById(song.RecordLabelId); if (recordlabel != null) { newSong.LabelId = recordlabel.RecordLabelId; } await _songRepository.AddSong(newSong); return(song); } catch (Exception ex) { throw ex; } }