public ActionResult DeleteConfirmed(string id) { try { ObjectId filmId = new ObjectId(id); FilmRepository.DeleteFilmById(filmId); return(RedirectToAction("Index")); } catch { return(RedirectToAction("Delete")); } }
/// <summary> /// Deleted an item from db /// </summary> private void DeleteItems() { Console.Clear(); Console.Clear(); Console.WriteLine("Delete an ITEM"); Console.WriteLine("--------------\n"); string itemType = ""; while (itemType.ToLower() != "b" && itemType.ToLower() != "f") { Console.Write("Select (b)ook or (f)ilm: "); itemType = Console.ReadLine(); } if (itemType.ToLower() == "b") { Console.Clear(); Console.WriteLine("Delete a BOOK"); Console.WriteLine("-------------\n"); List <Book> books = ShowBooks(); while (true) { Console.Write("\nEnter ID of BOOK to delete: "); string bookId = Console.ReadLine(); if (bookId.Length != 0 && IsDigitsOnly(bookId) && int.Parse(bookId) > 0 && int.Parse(bookId) <= books.Count) { int id = int.Parse(bookId) - 1; BookRepository.DeleteBookById(books[id].Id); Console.WriteLine($"\n** '{books[id].Title}' deleted SUCCESSFULLY **"); break; } } } else if (itemType.ToLower() == "f") { Console.Clear(); Console.WriteLine("Delete a FILM"); Console.WriteLine("-----------------\n"); List <Film> films = ShowFilms(); while (true) { Console.Write("\nEnter ID of FILM to delete: "); string filmId = Console.ReadLine(); if (filmId.Length != 0 && IsDigitsOnly(filmId) && int.Parse(filmId) > 0 && int.Parse(filmId) <= films.Count) { int id = int.Parse(filmId) - 1; FilmRepository.DeleteFilmById(films[id].Id); Console.WriteLine($"\n** {films[id].Title} deleted SUCCESSFULLY **"); break; } } } PressKeyToGoBackToStart(); }