public async Task <EditTrackFormModel> TrackEdit(int?trackId) { var track = await _context.Tracks .FirstOrDefaultAsync(t => t.Id == trackId); var result = new EditTrackFormModel { Name = track.Name, Duration = track.Duration, AlbumId = track.AlbumId, }; return(result); }
public async Task <IActionResult> Edit(int id, EditTrackFormModel track) { if (id != track.Id) { return(NotFound()); } var currTrack = new Track { Id = track.Id, Name = track.Name, Duration = track.Duration, AlbumId = track.AlbumId }; if (ModelState.IsValid) { try { _service.Edit( id, track.Name, track.Duration, track.AlbumId ); } catch (DbUpdateConcurrencyException) { if (!TrackExists(track.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } var currAlbum = await _albums.Albums(track.AlbumId); ViewData["AlbumId"] = new SelectList(currAlbum, "Id", "Name", track.AlbumId); return(View(track)); }