private void AddAudioMediaInternal(string title, string album, string artist, string filesystemId, bool isProtected) { // find or create artist entity var artistEntity = this.Artists.FirstOrDefault(x => x.Name.Trim().ToUpper() == artist.Trim().ToUpper()); if (artistEntity == null) { artistEntity = new Artist() { Name = artist }; base.ArtistDataService.Insert(artistEntity); this.Artists.Add(artistEntity); } // find or create album entity var albumEntity = artistEntity.Albums.FirstOrDefault(x => x.Title.Trim().ToUpper() == album.Trim().ToUpper()); if (albumEntity == null) { albumEntity = new Album() { ArtistId = artistEntity.Id, Title = album }; base.AlbumDataService.Insert(albumEntity); artistEntity.Albums.Add(albumEntity); this.Albums.Add(albumEntity); albumEntity.Artist = artistEntity; } // create audiomedia entity var audioMediaEntity = new AudioMedia() { AlbumId = albumEntity.Id, FilesystemId = filesystemId, Title = title, IsProtected = isProtected, }; base.AudioMediaDataService.Insert(audioMediaEntity); this.Songs.Add(audioMediaEntity); albumEntity.Songs.Add(audioMediaEntity); audioMediaEntity.Album = albumEntity; albumEntity.Artist = artistEntity; }
public DataAsyncResult UpdateArtist(Artist entity, TaskParam taskParam) { return this.EnqueueRequest(taskParam, () => { base.ArtistDataService.Update(entity); return null; }); }
public DataAsyncResult UpdateAudioMedia(AudioMedia entity, string title, string album, string artist, bool isProtected, List<int> playlistsToAdd, List<int> playlistsToRemove, TaskParam taskParam) { return this.EnqueueRequest(taskParam, () => { // find or create artist entity var artistEntity = this.Artists.FirstOrDefault(x => x.Name.Trim().ToUpper() == artist.Trim().ToUpper()); if (artistEntity == null) { artistEntity = new Artist() { Name = artist }; base.ArtistDataService.Insert(artistEntity); this.Artists.Add(artistEntity); } // find or create album entity var albumEntity = artistEntity.Albums.FirstOrDefault(x => x.Title.Trim().ToUpper() == album.Trim().ToUpper()); if (albumEntity == null) { albumEntity = new Album() { ArtistId = artistEntity.Id, Title = album }; base.AlbumDataService.Insert(albumEntity); artistEntity.Albums.Add(albumEntity); this.Albums.Add(albumEntity); albumEntity.Artist = artistEntity; } // update audiomedia entity int previousAlbumId = entity.Album.Id; entity.Title = title; entity.IsProtected = isProtected; entity.AlbumId = albumEntity.Id; entity.Album = albumEntity; base.AudioMediaDataService.Update(entity); // reflect changes into database and the cache if (previousAlbumId != albumEntity.Id) { albumEntity.Songs.Add(entity); var previousAlbum = this.Albums.FirstOrDefault(x => x.Id == previousAlbumId); previousAlbum.Songs.Remove(entity); if (previousAlbum.Songs.Count == 0) { var previousArtist = previousAlbum.Artist; base.AlbumDataService.Delete(new Album() { Id = previousAlbum.Id }); previousArtist.Albums.Remove(previousAlbum); this.Albums.Remove(previousAlbum); if (previousArtist.Albums.Count == 0) { base.ArtistDataService.Delete(new Artist() { Id = previousArtist.Id }); this.Artists.Remove(previousArtist); } } } foreach (var item in playlistsToAdd) { var playlist = this.Playlists.First(x => x.Id == item); this.AddAudioMediaToPlaylist(entity, playlist); } foreach (var item in playlistsToRemove) { var playlist = this.Playlists.First(x => x.Id == item); this.RemoveAudioMediaFromPlaylist(entity, playlist); } return null; }); }
public void Play(Artist artist) { this.PlayInternal(artist.AlbumsVisible.SelectMany(x => x.SongsVisible)); }