public ActionResult AddTrack(long playlistId, string id)
        {
            if (!ModelState.IsValid)
            {
                return(View("View"));
            }

            var track = trackProvider.LookupTrack(id);

            if (track == null)
            {
                return(new HttpStatusCodeResult(400));
            }

            var albumArtUrl = albumArtProvider.Find(track.Artist + " " + track.Title);

            track.CoverArtUrl = albumArtUrl;

            track = playlistManager.AddTrackToPlaylist(
                playlistId,
                track
                );

            if (track == null)
            {
                return(new HttpStatusCodeResult(400, "You can not add a song that is already in the list"));
            }
            var trackCount = playlistManager.ReadPlaylist(playlistId).PlaylistTracks.Where(p => p.PlayedAt == null).ToList().Count;

            return(Json(trackCount, JsonRequestBehavior.AllowGet));
        }
        public void Initialize()
        {
            playlistManager = new PlaylistManager(new PlaylistRepository(new EFDbContext(ContextEnum.BeatBuddyTest)), new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
            userManager     = new UserManager(new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
            user            = userManager.CreateUser("*****@*****.**", "matthias", "test", "acidshards", "");
            playlist        = playlistManager.CreatePlaylistForUser("testplaylist", "gekke playlist om te testen", "125", 5, true, "", user);

            trackProvider    = new YouTubeTrackProvider();
            albumArtProvider = new BingAlbumArtProvider();

            playlistControllerWithAuthenticatedUser = MyWebApi.Controller <PlaylistController>()
                                                      .WithResolvedDependencyFor <IPlaylistManager>(playlistManager)
                                                      .WithResolvedDependencyFor <IUserManager>(userManager)
                                                      .WithResolvedDependencyFor <ITrackProvider>(trackProvider)
                                                      .WithResolvedDependencyFor <IAlbumArtProvider>(albumArtProvider)
                                                      .WithAuthenticatedUser(
                u => u.WithIdentifier("NewId")
                .WithUsername(user.Email)
                .WithClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.Email))
                .WithClaim(new System.Security.Claims.Claim("sub", user.Email))
                );
            Track metallicaTrack = new Track()
            {
                Artist      = "Metallica",
                Title       = "Master of Puppets (live)",
                CoverArtUrl = "",
                Duration    = 800,
                TrackSource = new TrackSource
                {
                    SourceType = SourceType.YouTube,
                    Url        = "https://www.youtube.com/watch?v=kV-2Q8QtCY4",
                    TrackId    = "kV-2Q8QtCY4"
                }
            };
            Track nickelbackTrack = new Track()
            {
                Artist      = "Nickelback",
                Title       = "How You Remind Me",
                CoverArtUrl = "",
                Duration    = 400,
                TrackSource = new TrackSource
                {
                    SourceType = SourceType.YouTube,
                    Url        = "https://www.youtube.com/watch?v=1cQh1ccqu8M",
                    TrackId    = "1cQh1ccqu8M"
                }
            };

            _addedMetallicaTrack  = playlistManager.AddTrackToPlaylist(playlist.Id, metallicaTrack);
            _addedNickelbackTrack = playlistManager.AddTrackToPlaylist(playlist.Id, nickelbackTrack);
        }
        public IHttpActionResult AddTrack(long playlistId, string trackId)
        {
            var track = trackProvider.LookupTrack(trackId);

            if (track == null)
            {
                return(NotFound());
            }

            var albumArtUrl = albumArtProvider.Find(track.Artist + " " + track.Title);

            track.CoverArtUrl = albumArtUrl;

            track = playlistManager.AddTrackToPlaylist(
                playlistId,
                track
                );

            if (track == null)
            {
                return(NotFound());
            }

            return(Ok(track));
        }
Beispiel #4
0
        public ActionResult AddPlaylist(long playlistId, string id)
        {
            var youtubeProvider = new YouTubeTrackProvider();

            var tracks = youtubeProvider.LookUpPlaylist(id);

            foreach (Track track in tracks)
            {
                playlistManager.AddTrackToPlaylist(playlistId, track);
            }

            return(null);
        }
        public void Initialize() {
            playlistManager = new PlaylistManager(new PlaylistRepository(new EFDbContext(ContextEnum.BeatBuddyTest)), new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
            userManager = new UserManager(new UserRepository(new EFDbContext(ContextEnum.BeatBuddyTest)));
            user = userManager.CreateUser("*****@*****.**", "matthias", "test", "acidshards", "");
            playlist = playlistManager.CreatePlaylistForUser("testplaylist", "gekke playlist om te testen", "125", 5, true, "", user);

            trackProvider = new YouTubeTrackProvider();
            albumArtProvider = new BingAlbumArtProvider();

            playlistControllerWithAuthenticatedUser = MyWebApi.Controller<PlaylistController>()
               .WithResolvedDependencyFor<IPlaylistManager>(playlistManager)
               .WithResolvedDependencyFor<IUserManager>(userManager)
               .WithResolvedDependencyFor<ITrackProvider>(trackProvider)
               .WithResolvedDependencyFor<IAlbumArtProvider>(albumArtProvider)
               .WithAuthenticatedUser(
                u => u.WithIdentifier("NewId")
                      .WithUsername(user.Email)
                      .WithClaim(new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.Email))
                      .WithClaim(new System.Security.Claims.Claim("sub", user.Email))
               );
            Track metallicaTrack = new Track()
            {
                Artist = "Metallica",
                Title = "Master of Puppets (live)",
                CoverArtUrl = "",
                Duration = 800,
                TrackSource = new TrackSource
                {
                    SourceType = SourceType.YouTube,
                    Url = "https://www.youtube.com/watch?v=kV-2Q8QtCY4",
                    TrackId = "kV-2Q8QtCY4"
                }
            };
            Track nickelbackTrack = new Track()
            {
                Artist = "Nickelback",
                Title = "How You Remind Me",
                CoverArtUrl = "",
                Duration = 400,
                TrackSource = new TrackSource
                {
                    SourceType = SourceType.YouTube,
                    Url = "https://www.youtube.com/watch?v=1cQh1ccqu8M",
                    TrackId = "1cQh1ccqu8M"
                }
            };

            _addedMetallicaTrack = playlistManager.AddTrackToPlaylist(playlist.Id, metallicaTrack);
            _addedNickelbackTrack = playlistManager.AddTrackToPlaylist(playlist.Id, nickelbackTrack);
            
        }