public async Task <IActionResult> Edit(int id, [Bind("FavoriteSongId,SongURL,ApplicationUserId")] FavoriteSong favoriteSong)
        {
            if (id != favoriteSong.FavoriteSongId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(favoriteSong);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FavoriteSongExists(favoriteSong.FavoriteSongId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(favoriteSong));
        }
Exemple #2
0
 public void AddFavs(FavoriteSong fav)
 {
     using (var db = new SongContext(_connectionStrings))
     {
         db.FavoriteSongs.Add(fav);
         db.SaveChanges();
     }
 }
Exemple #3
0
 public void AddFavs(int songid, int userId)
 {
     if (GetFavSong(songid, userId) == null)
     {
         var fa = new FavoriteSong
         {
             SongId = songid,
             UserId = userId
         };
         AddFavs(fa);
     }
 }
        public async Task <IActionResult> Create([FromBody] FavoriteSong song)
        {
            if (song.FavoriteSongId == 0)
            {
                return(BadRequest("Invalid song id 0"));
            }

            if (ModelState.IsValid)
            {
                FavoriteSong favoriteSong = new FavoriteSong()
                {
                    SongURL         = $"http://localhost:5555/songs/{song.SongURL}",
                    SongTitle       = song.SongTitle,
                    ApplicationUser = await GetCurrentUserAsync()
                };
                _context.Add(favoriteSong);
                await _context.SaveChangesAsync();

                return(Ok(favoriteSong));
            }
            return(BadRequest(ModelState));
        }