private static void FillPlayListSongs(string playlistId, List<Song> playlistSongs, ApplicationDbContext db)
        {
            if (playlistSongs == null)
            {
                return;
            }

            for (int i = 0; i < playlistSongs.Count; i++)
            {
                var newRecord = new PlaylistItem
                {
                    SongId = playlistSongs[i].SongId,
                    AddDate = DateTime.Now,
                    PlaylistItemId = Guid.NewGuid().ToString(),
                    PlaylistId = playlistId,
                    TrackPos = i + 1
                };
                db.PlaylistItem.Add(newRecord);
            }
            //foreach (var song in playlistSongs)
            //{

            //}
        }
Example #2
0
        private static void CreateUpdateDefaultPlaylist(string songId, string userId, ApplicationDbContext db)
        {
            var user = (from entity in db.Users
                        where entity.Id == userId
                        select entity).FirstOrDefault();

            if (user != null && user.Playlist.Any(m => m.PlaylistId == userId) == false)
            {
                var defaultPlaylist = new Playlist
                {
                    AddDate = DateTime.Now,
                    PlaylistId = userId,
                    PlayListName = "Мои аудиозаписи",
                    DefaultPlaylist = true
                };

                db.Playlist.Add(defaultPlaylist);
                user.Playlist.Add(defaultPlaylist);

                var newRecord = new PlaylistItem
                {
                    SongId = songId,
                    AddDate = DateTime.Now,
                    PlaylistItemId = Guid.NewGuid().ToString(),
                    PlaylistId = defaultPlaylist.PlaylistId,
                    TrackPos = 1
                };

                db.PlaylistItem.Add(newRecord);
            }
            else
            {
                var defaultPlaylist = db.Playlist.FirstOrDefault(m => m.PlaylistId == userId);

                if (defaultPlaylist != null)
                {
                    var trackPos = db.PlaylistItem.Where(m => m.PlaylistId == defaultPlaylist.PlaylistId).Max(m => m.TrackPos);
                    var newRecord = new PlaylistItem
                    {
                        SongId = songId,
                        AddDate = DateTime.Now,
                        PlaylistItemId = Guid.NewGuid().ToString(),
                        PlaylistId = defaultPlaylist.PlaylistId,
                        TrackPos = trackPos + 1
                    };

                    db.PlaylistItem.Add(newRecord);
                }
            }
            db.SaveChanges();
        }
 private static void AddSongItemToPlayList(Song song, Playlist playlist, ApplicationDbContext db)
 {
     var newRecord = new PlaylistItem
     {
         SongId = song.SongId,
         AddDate = DateTime.Now,
         PlaylistItemId = Guid.NewGuid().ToString(),
         PlaylistId = playlist.PlaylistId,
     };
     db.PlaylistItem.Add(newRecord);
 }