public async Task <IActionResult> Delete(string id)
        {
            ListenedTo ListenedTo = await _context.ListenedTos.FindAsync(id);

            if (ListenedTo == null)
            {
                return(BadRequest());
            }

            _context.ListenedTos.Remove(ListenedTo);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IActionResult> Update(string id, [FromBody] ListenedTo value)
        {
            ListenedTo newListenedTo = await _context.ListenedTos.FindAsync(id);

            if (newListenedTo == null)
            {
                return(NoContent());
            }

            newListenedTo.fk_userID    = value.fk_userID;
            newListenedTo.fk_songID    = value.fk_songID;
            newListenedTo.dateListened = value.dateListened;

            await _context.SaveChangesAsync();

            return(Ok(newListenedTo));
        }
        public async Task <IActionResult> Post(string userID, string songName, string artistName)
        {
            Song ltSong = await _context.Songs.Where(s => s.songName == songName && s.artist == artistName).SingleOrDefaultAsync();

            if (ltSong == null)
            {
                using (HttpClient client = new HttpClient())
                {
                    try
                    {
                        string APIKEY = "451bb3863ad571f75d87164152f909ba";
                        client.BaseAddress = new Uri("http://api.onemusicapi.com");
                        HttpResponseMessage response = await client.GetAsync($"/20151208/release?user_key={APIKEY}&title={songName}&artist={artistName}");

                        response.EnsureSuccessStatusCode();

                        string stringResult = await response.Content.ReadAsStringAsync();

                        List <Release> rawSong = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Release> >(stringResult);

                        Release    release = rawSong.FirstOrDefault();
                        ListenedTo newLT   = null;
                        if (release != null)
                        {
                            ltSong = _addSong(release.title, release.artist, release.genre).Result;

                            newLT = new ListenedTo()
                            {
                                listenedToID = Guid.NewGuid().ToString(),
                                fk_songID    = ltSong.songID,
                                fk_userID    = userID,
                                dateListened = DateTime.Now
                            };

                            await _context.ListenedTos.AddAsync(newLT);

                            await _context.SaveChangesAsync();

                            foreach (Track t in release.media.FirstOrDefault().tracks)
                            {
                                await _addSong(t.title, release.artist, release.genre);
                            }
                        }

                        return(Ok(newLT));
                    }
                    catch (Exception e)
                    {
                        var rawSong = "rip";
                    }
                }
            }
            else
            {
                ListenedTo newLT = new ListenedTo()
                {
                    listenedToID = Guid.NewGuid().ToString(),
                    fk_songID    = ltSong.songID,
                    fk_userID    = userID,
                    dateListened = DateTime.Now
                };

                await _context.ListenedTos.AddAsync(newLT);

                await _context.SaveChangesAsync();

                return(Ok(newLT));
            }

            return(NoContent());
        }
        public async Task <IActionResult> Get(string id)
        {
            ListenedTo ListenedTo = await _context.ListenedTos.Where(u => u.listenedToID == id).SingleOrDefaultAsync();

            return(Ok(ListenedTo));
        }