public void EditSonglist(SonglistDTO songlistDTO, List <int> songIds) { if (songlistDTO == null) { throw new ArgumentNullException("Songlist Service - EditSonglist(...) songlistDTO cannot be null"); } using (var uow = UnitOfWorkProvider.Create()) { var songlist = songlistRepository.GetByID(songlistDTO.ID); if (songIds != null && songIds.Any()) { var songs = songRepository.GetByIDs(songIds); songlist.Songs.RemoveAll(song => !songs.Contains(song)); songlist.Songs.AddRange( songs.Where(song => !songlist.Songs.Contains(song))); } else { songlist.Songs.Clear(); } songlistRepository.Update(songlist); uow.Commit(); } }
/// <summary> /// Gets the songlist according to the ID /// </summary> /// <param name="songlistId">The songlist id</param> /// <returns>songlist according to ID</returns> private Songlist GetSongSonglist(int songlistID) { if (songlistID < 1) { throw new ArgumentOutOfRangeException("Song_Songlist Service - GetSongSonglist(...) songlistID cannot be lesser than 1"); } var songlist = songlistRepository.GetByID(songlistID); if (songlist == null) { throw new NullReferenceException("Song_SonglistService - GetSonglistOfSong(...) the songlist is null"); } return(songlist); }