public async Task <IActionResult> Edit(short id, [Bind("Id,Name,Description,IsActive")] Gender gender) { if (id != gender.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(gender); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenderExists(gender.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction(nameof(Index)); } return(PartialView("_EditPartial", gender)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,CoverImage,Title,Summary,ReleaseDate,CategoryId,PublisherId,AuthorId,LanguageId,NarratorId,AudioId,IsActive")] BookEditViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Book book = _mapper.Map <Book>(viewModel); if (viewModel.CoverImageFile != null) { _fileUpload.DeleteFile(viewModel.ExistingCoverImage, uploadImagePath); var result = _fileUpload.SaveFile(viewModel.CoverImageFile, uploadImagePath); book.CoverImage = result.UniqueFileName; } _context.Update(book); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(viewModel.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction(nameof(Index)); } var authors = _context.Authors.Select(s => new { Id = s.Id, FullName = string.Format("{0} {1}", s.FirstName, s.LastName) }); var narrators = _context.Narrators.Select(s => new { Id = s.Id, FullName = string.Format("{0} {1}", s.FirstName, s.LastName) }); ViewData["AudioId"] = new SelectList(_context.AudioFiles, "Id", "Name"); ViewData["AuthorId"] = new SelectList(authors, "Id", "FullName"); ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name"); ViewData["LanguageId"] = new SelectList(_context.Languages, "Id", "Name"); ViewData["NarratorId"] = new SelectList(narrators, "Id", "FullName"); ViewData["PublisherId"] = new SelectList(_context.Publishers, "Id", "Name"); return(PartialView("_EditPartial", viewModel)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,Name,Description,FileSize,FilePath,Duration,NormalizedName,CreatedBy,CreatedAt,ModifiedBy,ModifiedAt,IsActive")] AudioFile audioFile) { if (id != audioFile.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(audioFile); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AudioFileExists(audioFile.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(audioFile)); }
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)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ExistingImage,ImageFile,Name,Description,IsActive")] CategoryEditViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Category category = _mapper.Map <Category>(viewModel); if (viewModel.ImageFile != null) { _fileUpload.DeleteFile(viewModel.ExistingImage, uploadImagePath); var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath); category.Image = result.UniqueFileName; } _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(viewModel.Id)) { return(NotFound()); } else { throw; } } //return RedirectToAction(nameof(Index)); } return(PartialView("_EditPartial", viewModel)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,ImageFile,Name,Description,IsActive")] PublisherEditViewModel viewModel) { if (id != viewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { Publisher publisher = _mapper.Map <Publisher>(viewModel); if (viewModel.ImageFile != null) { _fileUpload.DeleteFile(viewModel.ExistingImage, uploadImagePath); var result = _fileUpload.SaveFile(viewModel.ImageFile, uploadImagePath); publisher.Image = result.UniqueFileName; } _context.Update(publisher); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PublisherExists(viewModel.Id)) { return(NotFound()); } else { throw; } } } return(PartialView("_EditPartial", viewModel)); }