public ActionResult Edit(ComicBooksEditViewModel viewModel) { ValidateComicBook(viewModel.ComicBook); if (ModelState.IsValid) { var comicBook = viewModel.ComicBook; _comicBooksRepository.Update(comicBook); TempData["Message"] = "Your comic book was successfully updated!"; return(RedirectToAction("Detail", new { id = comicBook.Id })); } viewModel.Init(Repository, _seriesRepo, _artistRepo); return(View(viewModel)); }
public ActionResult Edit(ComicBooksEditViewModel viewModel) { ValidateComicBook(viewModel.ComicBook); if (ModelState.IsValid) { var comicBook = viewModel.ComicBook; // TODO Update the comic book. TempData["Message"] = "Your comic book was successfully updated!"; return(RedirectToAction("Detail", new { id = comicBook.Id })); } viewModel.Init(); return(View(viewModel)); }
public ActionResult Edit(ComicBooksEditViewModel viewModel) { ValidateComicBook(viewModel.ComicBook); if (ModelState.IsValid) { var comicBook = viewModel.ComicBook; try { _comicBooksRepository.Update(comicBook); TempData["Message"] = "Your comic book was successfully updated!"; return(RedirectToAction("Detail", new { id = comicBook.Id })); } catch (DbUpdateConcurrencyException ex) { string message = null; var entityPropertyValues = ex.Entries.Single().GetDatabaseValues(); if (entityPropertyValues == null) { message = "The comic book being updated has been deleted by another user. Click the 'Cancel' Button to return to the list page."; viewModel.ComicBookHasBeenDeleted = true; } else { message = "The comic book being updated has already been updated by another user. If you still want to make your changes than click the 'Save' button again. Otherwise click the 'Cancel' button to discard your changes."; comicBook.RowVersion = ((ComicBook)entityPropertyValues.ToObject()).RowVersion; } ModelState.AddModelError(string.Empty, message); } } viewModel.Init(Repository); return(View(viewModel)); }
public ActionResult Edit(ComicBooksEditViewModel viewModel) { ValidateComicBook(viewModel.ComicBook); if (ModelState.IsValid) { var comicBook = viewModel.ComicBook; Context.Entry(comicBook).State = EntityState.Modified; Context.SaveChanges(); TempData["Message"] = "Your comic book was successfully updated!"; return(RedirectToAction("Detail", new { id = comicBook.Id })); } viewModel.Init(Context); return(View(viewModel)); }
public ActionResult Edit(ComicBooksEditViewModel viewModel) { ValidateComicBook(viewModel.ComicBook); if (ModelState.IsValid) { var comicBook = viewModel.ComicBook; try { _comicBooksRepository.Update(comicBook); TempData["Message"] = "Your comic book was successfully updated!"; return(RedirectToAction("Detail", new { id = comicBook.Id })); } catch (DbUpdateConcurrencyException e) { string message = null; var entityPropertyValues = e.Entries.Single().GetDatabaseValues(); if (entityPropertyValues == null) { message = "Another user deleted this comicbook while you were attempting to edit. Click 'Cancel' to return to the list."; viewModel.ComicBookHasBeenDeleted = true; } else { message = "The comicbook was updated by another user. If you still want to save your changes, click 'Save' again. Otherwise click 'Cancel' to discard changes."; comicBook.RowVersion = ((ComicBook)entityPropertyValues.ToObject()).RowVersion; } ModelState.AddModelError(string.Empty, message); } } viewModel.Init(Repository, _seriesRepository, _artistsRepository); return(View(viewModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var comicBook = _comicBooksRepository.Get((int)id, includeRelatedEntities: false); if (comicBook == null) { return(HttpNotFound()); } var viewModel = new ComicBooksEditViewModel() { ComicBook = comicBook }; viewModel.Init(Repository, _seriesRepository, _artistsRepository); return(View(viewModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var comicBook = comicBooksRepository.Get(id.Value, true); if (comicBook == null) { return(HttpNotFound()); } var viewModel = new ComicBooksEditViewModel() { ComicBook = comicBook }; viewModel.Init(Repository); return(View(viewModel)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // TODO Get the comic book. var comicBook = new ComicBook(); if (comicBook == null) { return(HttpNotFound()); } var viewModel = new ComicBooksEditViewModel() { ComicBook = comicBook }; viewModel.Init(); return(View(viewModel)); }