public ActionResult Delete(ComicBooksDeleteViewModel viewModel)
        {
            try
            {
                _comicBooksRepository.Delete(viewModel.ComicBook.Id, viewModel.ComicBook.RowVersion);

                TempData["Message"] = "Your comic book was successfully deleted!";

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                string message = null;

                var entityPropertyValues = ex.Entries.Single().GetDatabaseValues();

                if (entityPropertyValues == null)
                {
                    message = "The comic book being deleted 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 deleted has already been updated by another user. If you still want to delete the comic book than click the 'Delete' button again. Otherwise click the 'Cancel' button to return to the detail page.";

                    viewModel.ComicBook.RowVersion = ((ComicBook)entityPropertyValues.ToObject()).RowVersion;
                }

                ModelState.AddModelError(string.Empty, message);

                return(View(viewModel));
            }
        }
        public ActionResult Delete(ComicBooksDeleteViewModel viewModel)
        {
            try {
                _comicBooksRepository.Delete(
                    viewModel.ComicBook.Id,
                    viewModel.ComicBook.RowVersion);

                TempData["Message"] = "Your comic book was successfully deleted!";

                return(RedirectToAction("Index"));
            }
            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 delete it. Click 'Cancel' to return to the list.";

                    viewModel.ComicBookHasBeenDeleted = true;
                }
                else
                {
                    message = "The comicbook was updated by another user while you were attempting to delete it. If you still want to delete it, click 'Delete' again. Otherwise click 'Cancel' to navigate back to list.";

                    viewModel.ComicBook.RowVersion = ((ComicBook)entityPropertyValues.ToObject()).RowVersion;
                }

                ModelState.AddModelError(string.Empty, message);

                return(View(viewModel));
            }
        }
        public ActionResult Delete(ComicBookDeleteViewModel viewModel)
        {
            try
            {
                _comicBooksRepository.Delete(viewModel.Id, viewModel.ComicBook.RowVersion);

                TempData["Message"] = "Your comic book was successfully deleted!";

                return(RedirectToAction("Index"));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var entityProperty = ex.Entries.Single().GetDatabaseValues();
                if (entityProperty != null)
                {
                    TempData["EditErrors"] = "Your loaded comic was changed by another user";
                    return(RedirectToAction("Edit", new { id = ((ComicBook)entityProperty.ToObject()).Id }));
                }
                else
                {
                    TempData["Error"] = "Your loaded entity was already delete by someone else";
                }
            }

            return(View(viewModel));
        }
        public ActionResult Delete(int id)
        {
            _comicBooksRepository.Delete(id);

            TempData["Message"] = "Your comic book was successfully deleted!";

            return(RedirectToAction("Index"));
        }
Example #5
0
        /// <summary>
        /// Confirms that the user wants to delete the comic book
        /// for the provided comic book ID and if so, deletes the
        /// comic book from the database.
        /// </summary>
        /// <param name="comicBookId">The comic book ID to delete.</param>
        /// <returns>Returns "true" if the comic book was deleted, otherwise "false".</returns>
        private static bool DeleteComicBook(int comicBookId)
        {
            _comicBookRepository = new ComicBooksRepository(context);
            var successful = false;

            // Prompt the user if they want to continue with deleting this comic book.
            string input = ConsoleHelper.ReadInput(
                "Are you sure you want to delete this comic book (Y/N)? ", true);

            // If the user entered "y", then delete the comic book.
            if (input == "y")
            {
                _comicBookRepository.Delete(comicBookId);
                successful = true;
            }

            context.Dispose();
            return(successful);
        }