// GET: Tracks/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userGuid = User.Identity.GetUserId(); var currentListener = db.Listeners.FirstOrDefault(l => l.UserGuid == userGuid); Track trackInDb = await db.Tracks.Include(t => t.Album).Include(t => t.Artist).FirstOrDefaultAsync(t => t.TrackId == id); if (trackInDb == null) { return(HttpNotFound()); } if (trackInDb.TrackAcousticness is null) { trackInDb = await SpotifyInteractionController.GetSpotifyTrackDetails(currentListener, trackInDb); db.SaveChanges(); } return(View(trackInDb)); }
public async Task <ActionResult> PickArtists() { var currentListener = GetCurrentListener(); var artists = new List <Artist>(); var genres = new List <Genre>(); if (!db.Genres.Any()) { await SpotifyInteractionController.SpotifyGenerateGenreSeeds(currentListener); } genres.AddRange(db.Genres.AsNoTracking().ToList()); List <Task <Artist> > artistTask = new List <Task <Artist> >(); for (int i = 0; i < 25; i++) { var genre = genres[Randomness.RandomInt(0, genreSeedCount)]; artistTask.Add(SpotifyInteractionController.SpotifySearchForArtistInGenre(genre, currentListener)); } foreach (var task in artistTask) { var artist = await task; if (artist != null && artists.FirstOrDefault(a => a.ArtistSpotifyId == artist.ArtistSpotifyId) is null) { artists.Add(artist); } } return(View(artists)); }
// GET: Albums/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Album albumInDb = await db.Albums.Include(a => a.AlbumTracks).Include(a => a.Artist).FirstOrDefaultAsync(a => a.AlbumId == id); if (albumInDb == null) { return(HttpNotFound()); } if (albumInDb.AlbumTracks.Count != albumInDb.AlbumTotalTracks) { string userGuid = User.Identity.GetUserId(); var currentListener = db.Listeners.FirstOrDefault(l => l.UserGuid == userGuid); if (currentListener is null) { Console.WriteLine("User is not logged in"); return(RedirectToAction("Index", "Home")); } albumInDb = await SpotifyInteractionController.GetSpotifyAlbumDetails(currentListener, albumInDb); } return(View(albumInDb)); }
public async Task <ActionResult> AuthResponse(string code, string state) { var currentListener = GetCurrentListener(); var result = await SpotifyInteractionController.PostSpotifyOauthToReceiveSpotifyAuthAndRefreshToken(code, state, currentListener); currentListener.AccessToken = result.access_token; currentListener.RefreshToken = result.refresh_token; db.SaveChanges(); return(RedirectToAction("PickArtists")); }
public async Task <ActionResult> Create(Playlist playlist) { if (ModelState.IsValid) { if (playlist.PlaylistMood != null) { playlist.Mood = await db.Moods.FindAsync(playlist.PlaylistMood); } var currentListener = GetCurrentListener(); playlist.CreatedBy = db.Listeners.Find(currentListener.ListenerId).ListenerId; var playlistTrackTasks = new List <Task <List <Track> > >(); var playlistTracks = new List <Track>(); for (int i = 0; i < 30; i++) { playlistTrackTasks.Add(SpotifyInteractionController.SpotifySearchForRecommendedTracks(currentListener, playlist)); //var tracks = await SpotifyInteractionController.SpotifySearchForRecommendedTracks(currentListener, playlist); //if (tracks is null) //{ // continue; //} //playlistTracks.AddRange(tracks); } foreach (var task in playlistTrackTasks) { var tracks = await task; if (tracks != null) { playlistTracks.AddRange(tracks); } } playlist.PlaylistTracks = playlistTracks.Distinct().ToList(); //playlist.Listener = currentListener; var playlistInDb = db.Playlists.Add(playlist); db.SaveChanges(); return(RedirectToAction("Details", new { id = playlistInDb.PlaylistId })); } return(RedirectToAction("Index")); }
public ActionResult SpotifyLogin() { ViewBag.SpotifyAuthorizationUri = SpotifyInteractionController.GetSpotifyAuthorization(); return(View()); }