public async Task <IActionResult> Create([Bind("Id,Name,ArtistId,ReleaseDate")] Album album) { if (ModelState.IsValid) { _context.Add(album); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ArtistId"] = new SelectList(_context.Artists, "Id", "Name", album.ArtistId); return(View(album)); }
public async Task <IActionResult> Create([Bind("Id,Name,Duration,AlbumId,ArtistId")] Song song) { if (ModelState.IsValid) { _context.Add(song); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["AlbumId"] = new SelectList(_context.Albums, "Id", "Name", song.AlbumId); ViewData["ArtistId"] = new SelectList(_context.Artists, "Id", "Name", song.ArtistId); return(View(song)); }
[ValidateAntiForgeryToken]//[Bind("Id,Name,Description,UserId")] public async Task <IActionResult> Create([Bind("Id,Name,Description,UserId,SongId")] Catalog catalog, string[] SongId) { if (ModelState.IsValid) { var u = AccountService.UsrId; var usr = _context.Users.FirstOrDefault(x => x.Id == u); catalog.UserId = usr.Id; catalog.User = usr; foreach (var s in SongId) { var song = _context.Songs.FirstOrDefault(x => x.Name == s); catalog.Songs.Add(song); } _context.Add(catalog); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Name", catalog.UserId); ViewData["SongId"] = new SelectList(_context.Users, "Id", "Name", catalog.Songs); return(View(catalog)); }