Example #1
0
        public bool UpdateHistory(History history)
        {
            bool hasUpdated = false;
            if (history != null)
            {
                HistoryEntity entity = new HistoryEntity
                {
                    AppID = history.AppId,
                    TitelID = history.AlbumId,
                    LiedID = history.TrackId,
                    Zeit = history.PlayedAt,
                    Benutzer = history.UserName,
                    Interpret = string.Empty,
                    Titel = string.Empty,
                    Lied = string.Empty
                };

                using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
                {
                    tunesEntity.history.Add(entity);
                    hasUpdated = tunesEntity.SaveChanges() > 0;
                }
            }
            return hasUpdated;
        }
Example #2
0
 public bool DeletePlaylists(IList<Playlist> playlists)
 {
     bool hasDeleted = false;
     if (playlists != null)
     {
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             foreach (var playlist in playlists)
             {
                 if (playlist != null)
                 {
                     var entryEntities = tunesEntity.playlistentries.Where(entry => entry.PlaylistId == playlist.Id);
                     if (entryEntities != null)
                     {
                         foreach (var entry in entryEntities)
                         {
                             if (entry != null)
                             {
                                 tunesEntity.playlistentries.Remove(entry);
                             }
                         }
                     }
                     var playlistEntity = tunesEntity.playlist.Where(list => list.ListId == playlist.Id).FirstOrDefault();
                     if (playlistEntity != null)
                     {
                         tunesEntity.playlist.Remove(playlistEntity);
                     }
                 }
             }
             tunesEntity.SaveChanges();
             hasDeleted = true;
         }
     }
     return hasDeleted;
 }
Example #3
0
 public Playlist AppendToPlaylist(Playlist playlist)
 {
     if (playlist != null && playlist.Entries != null)
     {
         List<PlaylistEntry> entries = new List<PlaylistEntry>(playlist.Entries);
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             if (tunesEntity != null)
             {
                 int sortOrder = tunesEntity.playlistentries.Where(pe => pe.PlaylistId == playlist.Id).Count();
                 entries.ForEach((playlistEntry) =>
                     {
                         if (playlistEntry != null)
                         {
                             tunesEntity.playlistentries.Add(new PlaylistEntryEntity
                             {
                                 Guid = playlistEntry.Guid,
                                 LiedId = playlistEntry.TrackId,
                                 PlaylistId = playlist.Id,
                                 sortorder = sortOrder,
                                 Timestamp = DateTime.Now
                             });
                         }
                     });
                 tunesEntity.SaveChanges();
             }
         }
     }
     return playlist = this.GetPlaylistById(playlist.Id, playlist.UserName);
 }
Example #4
0
 public bool UpdatePlaylistEntries(Playlist playlist)
 {
     bool hasUpdated = false;
     if (playlist != null && playlist.Entries != null)
     {
         List<PlaylistEntry> entries = new List<PlaylistEntry>(playlist.Entries);
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             if (tunesEntity != null)
             {
                 var entr = tunesEntity.playlistentries.Where((e) => e.PlaylistId == playlist.Id).ToList();
                 entr.ForEach((e) =>
                 {
                     if (e != null)
                     {
                         tunesEntity.playlistentries.Remove(e);
                     }
                 });
                 foreach (var e in playlist.Entries)
                 {
                     if (e != null)
                     {
                         PlaylistEntryEntity entity = new PlaylistEntryEntity
                         {
                             Guid = e.Guid,
                             LiedId = e.TrackId,
                             PlaylistId = playlist.Id,
                             Timestamp = DateTime.Now,
                             sortorder = e.SortOrder
                         };
                         tunesEntity.playlistentries.Add(entity);
                     }
                 }
                 tunesEntity.SaveChanges();
                 hasUpdated = true;
             }
         }
     }
     return hasUpdated;
 }
Example #5
0
 public Playlist InsertPlaylist(Playlist playlist)
 {
     if (playlist != null)
     {
         PlaylistEntity entity = new PlaylistEntity
         {
             ListId = playlist.Id,
             ListName = playlist.Name,
             User = playlist.UserName,
             guid = playlist.Guid.ToString(),
             Timestamp = DateTime.Now
         };
         using (TunesEntities tunesEntity = new TunesEntities(this.ConnectionString))
         {
             PlaylistEntity playlistEntity = tunesEntity.playlist.FirstOrDefault(pl => pl.ListId == playlist.Id);
             if (playlistEntity == null)
             {
                 if (tunesEntity.playlist.FirstOrDefault(
                     pl => string.Compare(pl.ListName, entity.ListName) == 0 && string.Compare(pl.User, entity.User) == 0) != null)
                 {
                     string playlistExistsExceptionMessage = string.Format(CultureInfo.InvariantCulture, SRResources.PlaylistExistsException, playlist.Name);
                     throw new PlaylistExistsException(playlistExistsExceptionMessage);
                 }
                 tunesEntity.playlist.Add(entity);
             }
             tunesEntity.SaveChanges();
             playlist = new Playlist
             {
                 Id = entity.ListId,
                 Name = entity.ListName,
                 UserName = entity.User,
                 Guid = new Guid(entity.guid)
             };
         }
     }
     return playlist;
 }