Ejemplo n.º 1
0
        public ActionResult Delete(ComicBookDeleteViewModel 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 comicbook being deleted has been deleted by another user. click the 'Cancel' to return to home.";

                    viewModel.ComicBookHasBeenDeleted = true;
                }
                else
                {
                    message = "The comicbook being deleted has already been updated by another user. If you still want to delete the comicbook than click the 'Delete' button again. Otherwise click the 'Cancel' button to return to home.";

                    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));
        }
Ejemplo n.º 3
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            var comicBook = _comicBooksRepository.Get((int)id);

            if (comicBook == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new ComicBookDeleteViewModel()
            {
                ComicBook = comicBook
            };

            return(View(viewModel));
        }