public async Task <IActionResult> Jukebox() { //check if user forcely quit editing the playlist and delete it var appUser = await _userManager.GetUserAsync(User); var user = await _jukeboxRepository.GetUserAsync(appUser.Id); var myPlaylists = await _jukeboxRepository.GetAllFilteredPlaylistsAsync(p => p.User.Id.Equals(user.Id)); var playlist = myPlaylists.FirstOrDefault(p => !p.IsCreated); if (playlist != null) { var playlistUser = playlist.User; playlistUser.Playlists.Remove(playlist); //sending playlistUser cause current user can be admin and other users can't even reach this method await _jukeboxRepository.RemovePlaylistAsync(playlist.Id, playlistUser.Id); await _jukeboxRepository.UpdateUserAsync(playlistUser, playlistUser.Id); } var allPlaylists = await _jukeboxRepository.GetAllPlaylistsAsync(); var model = new JukeboxViewModel(allPlaylists); return(View(model)); }
public async Task <IActionResult> MyPlaylists() { var appUser = await _userManager.GetUserAsync(User); var user = await _jukeboxRepository.GetUserAsync(appUser.Id); var myPlaylists = await _jukeboxRepository.GetAllFilteredPlaylistsAsync(playlist => playlist.User.Id.Equals(user.Id)); var playlists = await _jukeboxRepository.GetAllPlaylistsAsync(); var model = new MyPlaylistsViewModel(StatusMessage, myPlaylists, playlists, user); return(View(model)); }