// GET: Narrators/Edit/5 public async Task <IActionResult> Edit(long?id) { if (id == null) { return(NotFound()); } var narrator = await _context.Narrators.FindAsync(id); if (narrator == null) { return(NotFound()); } NarratorEditViewModel viewModel = _mapper.Map <NarratorEditViewModel>(narrator); ViewData["GenderId"] = new SelectList(_context.Genders, "Id", "Name"); return(PartialView("_EditPartial", viewModel)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,ImageFile,FirstName,LastName,OtherName,GenderId,EmailAddress,PhoneNumber,HouseAddress,IsActive")] NarratorEditViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Narrator narrator = _mapper.Map <Narrator>(viewModel); if (viewModel.ImageFile != null) { _fileUpload.DeleteFile(viewModel.ExistingImage, uploadImagePath); var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath); narrator.Image = result.UniqueFileName; } _context.Update(narrator); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NarratorExists(viewModel.Id)) { return(NotFound()); } else { throw; } } } ViewData["GenderId"] = new SelectList(_context.Genders, "Id", "Name"); return(PartialView("_EditPartial", viewModel)); }