public async Task <ActionResult> Edit(int id, AlbumUpdateViewModel albumUpdateViewModel) { var model = await _albumService.GetByIdAsync(id); if (model == null) { // return NotFound(); return(View(albumUpdateViewModel)); } try { model.Artist = albumUpdateViewModel.Artist; model.Title = albumUpdateViewModel.Title; model.CoverUrl = albumUpdateViewModel.CoverUrl; model.ReleaseDate = albumUpdateViewModel.ReleaseDate; model.Price = albumUpdateViewModel.Price; await _albumService.UpdateAsync(model); return(RedirectToAction(nameof(Index))); } catch { return(View(albumUpdateViewModel)); } }
public async Task <IActionResult> Edit(int id, AlbumUpdateViewModel albumUpdateViewModel) { var album = await _albumService.GetByIdAsync(id); if (album == null) { return(RedirectToAction("Index")); } _mapper.Map(albumUpdateViewModel, album); await _albumService.UpdateAsync(album); return(RedirectToAction("Details", new { id = album.Id })); }
// GET: Album/Edit/5 public async Task<ActionResult> Edit(int id) { var model = await _albumService.GetByIdAsync(id); if (model == null) { return RedirectToAction(nameof(Index)); } var editModel = new AlbumUpdateViewModel { Artist = model.Artist, Title = model.Title, CoverUrl = model.CoverUrl, Price = model.Price, ReleaseDate = model.ReleaseDate }; return View(editModel); }