public async Task <IActionResult> CreateAsync([Bind("Name,ArtistName,Length,ReleaseDate,TrackNumber,Publisher,AlbumId")] Song song) { ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (ModelState.IsValid) { song.ArtistId = currentUser.Id; song.Artist = currentUser; _context.Add(song); await _context.SaveChangesAsync(); return(RedirectToAction("Admin")); } ViewData["AlbumId"] = (IEnumerable <SelectListItem>)BuildUserAlbumsDropDownList(currentUser); return(View(song)); }
public async Task <IActionResult> Create([Bind("Publisher,Name,ArtistName,ReleaseDate")] Album album) { ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name); if (currentUser == null) { throw new Exception("Cannot find user."); } album.ArtistId = currentUser.Id; album.Artist = currentUser; if (ModelState.IsValid) { _context.Add(album); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["ArtistId"] = new SelectList(_context.Users, "Id", "Id", album.ArtistId); return(View(album)); }