Exemplo n.º 1
0
        public async Task <IActionResult> PutPlaylistSongList(int id, PlaylistSongList playlistSongList)
        {
            if (id != playlistSongList.PlaylistId)
            {
                return(BadRequest());
            }

            _context.Entry(playlistSongList).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaylistSongListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task AddSongsToPlaylistDatabase(int startPosition)
        {
            string[] PlaylistArray = ReadPlaylistFromLine(startPosition);

            for (int i = 0; i < PlaylistArray.Length; i++)
            {
                if (PlaylistArray[i].Substring(PlaylistArray[i].Length - 4)[0].Equals('.'))
                {
                    string songInfo = PlaylistArray[i].Remove(0, PlaylistArray[i].LastIndexOf('\\') + 1);
                    songInfo = songInfo.Remove(songInfo.Length - 4);
                    int      tmpSeparator    = songInfo.IndexOf("-");
                    string   leadAuthor      = songInfo.Remove(tmpSeparator - 1);
                    string[] leadAuthorArray = leadAuthor.Split(',');
                    string   title           = songInfo.Remove(0, tmpSeparator + 2);

                    if (title.Contains("(feat"))
                    {
                        int tmpFeat = title.IndexOf("(feat");
                        title = title.Remove(tmpFeat - 1);
                    }

                    for (int i1 = 0; i1 < SongList.Count; i1++)
                    {
                        if (leadAuthorArray[0] == SongList[i1].LeadAuthorList[0] && title == SongList[i1].Title)
                        {
                            Playlist playlistSong = new Playlist(SongInPlaylistId, SongList[i1].Id, false);
                            PlaylistSongList.Add(playlistSong);
                            SongInPlaylistId++;
                        }
                    }
                }
            }

            try
            {
                HttpResponseMessage playlistDatabaseResponse = await HttpClientServer.PostAsJsonAsync("api/playlists/add", PlaylistSongList);

                if (playlistDatabaseResponse.IsSuccessStatusCode)
                {
                }
                else
                {
                    ServerStatus = "Server fail, try again!";
                    MessageBox.Show("Server fail, try again!");
                }
            }
            catch
            {
                IsServerStartButtonEnabled = true;
                ServerStatus = "Server fail, try again!";
                MessageBox.Show("Server fail, try again!");
            }
        }
Exemplo n.º 3
0
        public async Task UpdatePlaylist()
        {
            int             counterPlayedSongs = 0;
            List <Playlist> playedSongsList    = new List <Playlist>();

            for (int i = 0; i < PlaylistSongList.Count; i++)
            {
                if (PlaylistSongList[i].WasPlayed == false)
                {
                    break;
                }
                playedSongsList.Add(PlaylistSongList[i]);
                counterPlayedSongs++;
            }
            SongInPlaylistId   = counterPlayedSongs + 1;
            counterPlayedSongs = counterPlayedSongs * 2;
            PlaylistSongList.Clear();
            PlaylistSongList.AddRange(playedSongsList);
            await AddSongsToPlaylistDatabase(counterPlayedSongs);
        }
Exemplo n.º 4
0
        public async Task <ActionResult <PlaylistSongList> > PostPlaylistSongList(PlaylistSongList playlistSongList)
        {
            _context.PlaylistSongLists.Add(playlistSongList);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PlaylistSongListExists(playlistSongList.PlaylistId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPlaylistSongList", new { id = playlistSongList.PlaylistId }, playlistSongList));
        }