public PlaylistSongs AddSongToPlaylist(PlaylistSongs playlistSongs) { if (playlistSongs.songID != 0 & playlistSongs.playlistID != 0) { SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[Playlist_Songs] (SongID, PlaylistID) values (@SongID, @PlaylistID)", con); cmd.Parameters.AddWithValue("@SongID", playlistSongs.songID); cmd.Parameters.AddWithValue("@PlaylistID", playlistSongs.playlistID); con.Open(); cmd.ExecuteNonQuery(); con.Close(); return(playlistSongs); } else { return(playlistSongs); } }
public IActionResult Add(int selectedPlaylist, int selectedSong) { PlaylistSongs playlistSongs = new PlaylistSongs(); try { playlistSongs.playlistID = selectedPlaylist; playlistSongs.songID = selectedSong; playlistContainer.AddSongPlaylist(playlistSongs); ViewBag.SuccesOrNot = "Song saved to playlist!"; } catch { ViewBag.SuccesOrNot = "ERROR! Song did not save to playlist"; } return(Customer()); }
private async void OpenSongMenu(Song obj) { var choice = await pageDialogService.DisplayActionSheetAsync("Options", "Close", "", new string[] { "Remove from Playlist", "Go to Band Page" }); if (choice.Equals("Remove from Playlist")) { var remove = await pageDialogService.DisplayAlertAsync("", "Do you really want to remove this song from the playlist?", "OK", "CANCEL"); if (remove) { if (await Singleton.Instance.webService.RemoveSongFromPlaylist(playlist.PlId.ToString(), obj.SongId.ToString())) { PlaylistSongs.Remove(obj); } } } }
public async Task <ActionResult <PlaylistSongs> > PostPlaylistSongs(PlaylistSongs playlistSongs) { var user = await userManager.FindByNameAsync(User.Identity.Name); if (user == null) { return(Unauthorized(new Response { Status = "Fail", Message = "I don't know how you could possibly get this error message but you managed to do it" })); } var playlist = await _context.Playlist.Where(x => x.Id == playlistSongs.PlaylistId).FirstOrDefaultAsync(); if (playlist.UserID != user.Id) { return(Unauthorized(new Response { Status = "Fail", Message = "You do not own this playlist" })); } _context.PlaylistSongs.Add(playlistSongs); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPlaylistSongs", new { id = playlistSongs.Id }, playlistSongs)); }
public void SeedSong() { if (!musicContext.Songs.Any()) { Artist artist = new Artist { Name = "Plini", }; Album album1 = new Album { Name = "Other Things", Songs = new List <Song>(), ArtistId = 1, DateTimeCreated = DateTime.Parse("2020-9-19-11:35") }; Song song1 = new Song { Name = "Selenium Forest", Length = 6.05, AlbumId = 1, DateTimeCreated = DateTime.Parse("2020-9-19-11:35") }; Song song2 = new Song { Name = "Electric Sunrise", Length = 5.50, AlbumId = 1, DateTimeCreated = DateTime.Parse("2020-9-19-1:35") }; Playlist playlist1 = new Playlist { Name = "Plini is good", Public = true, }; PlaylistSongs playlistSongs1 = new PlaylistSongs { SongId = 1, PlaylistId = 1, }; PlaylistSongs playlistSongs2 = new PlaylistSongs { SongId = 2, PlaylistId = 1, }; musicContext.Artists.Add(artist); musicContext.SaveChanges(); musicContext.Albums.Add(album1); musicContext.SaveChanges(); musicContext.Songs.Add(song1); musicContext.Songs.Add(song2); musicContext.SaveChanges(); musicContext.Playlist.Add(playlist1); musicContext.SaveChanges(); musicContext.PlaylistSongs.Add(playlistSongs1); musicContext.SaveChanges(); musicContext.PlaylistSongs.Add(playlistSongs2); musicContext.SaveChanges(); } }