public async Task <IActionResult> PutSong(int id, Song song) { if (id != song.Id) { return(BadRequest()); } _context.Entry(song).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SongExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("Id,Name,ArtistId,GenreId")] Song song) { if (ModelState.IsValid) { _context.Add(song); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(song)); }
public async Task <IActionResult> Create([Bind("Id,Name")] Artist artist) { if (ModelState.IsValid) { _context.Add(artist); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(artist)); }
public async Task <IActionResult> Create([Bind("Id,UserId,PostId")] CreateFavorite favorite) { if (ModelState.IsValid) { _context.Add(favorite); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["PostId"] = new SelectList(_context.Posts, "Id", "SongId", favorite.PostId); ViewData["UserId"] = new SelectList(_context.Users, "Id", "UserName", favorite.UserId); return(View(favorite)); }
public async Task <IActionResult> Show(int?id) { if (id == null) { return(NotFound()); } var post = await _context.Posts .Include(p => p.Artist) .Include(p => p.Song) .FirstOrDefaultAsync(m => m.Id == id); if (post == null) { return(NotFound()); } post.ViewCount++; await _context.SaveChangesAsync(); return(View(post)); }