public ActionResult DeleteMovie(int Id) { Movie deleteMovie = movieRepository.GetMovie(Id); if (deleteMovie.ImagePath != null) { DeleteImage(deleteMovie.ImagePath); } movieRepository.Delete(deleteMovie); movieRepository.Save(); return(RedirectToAction("ManageListOfMovies", "Movie")); }
public ActionResult Delete(string id, FormCollection collection) { try { // TODO: Add delete logic here rep.Delete(id); rep.Save(); return(RedirectToAction("Index")); } catch { return(View()); } }
public Movie Delete(int id) { var existed = GetDetail(id); if (existed.ShowTimes.Any()) { throw new Exception("Can not delete Movie that already had Showtimes"); } if (existed.Img != null) { fileService.Remove(existed.Img); } return(repository.Delete(id)); }
public ActionResult Delete(int id, Movie movie) { try { MovieRepository movieRepository = new MovieRepository(); using (movieRepository) { movieRepository.Delete(id); } return(RedirectToAction("Index")); } catch { return(View()); } }
public void Delete_removes_entity() { // Arrange var builder = new DbContextOptionsBuilder <Database>(); builder.UseInMemoryDatabase(databaseName: "Delete_removes_entity"); var context = new Database(builder.Options); InitDbContext(context); var repo = new MovieRepository(context); // Act repo.Delete(2); // Assert Assert.Equal(expected: 2, actual: context.Movies.Count()); }
public ActionResult Delete(int id, Movie movie) { try { MovieRepository movieRepository = new MovieRepository(); using (movieRepository) { movieRepository.Delete(id); } return RedirectToAction("Index"); } catch { // TODO Add view for error message return View(); } }
/// <summary> /// Removes the movie request. /// </summary> /// <param name="requestId">The request identifier.</param> /// <returns></returns> public async Task <RequestEngineResult> RemoveMovieRequest(int requestId) { var request = await MovieRepository.GetAll().FirstOrDefaultAsync(x => x.Id == requestId); var result = await CheckCanManageRequest(request); if (result.IsError) { return(result); } await MovieRepository.Delete(request); await _mediaCacheService.Purge(); return(new RequestEngineResult { Result = true, }); }
public void DeleteGenre(Genre genre) { var result = MessageBox.Show( string.Format(Resources.DeleteGenreConfirmationText, genre.Name), Resources.DeleteConfirmationCaption, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { try { repository.Delete(genre); RetrieveData(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public IActionResult Delete(string id) { if (HttpContext.Session.GetObjectFromJson <User>("loggedUser") == null) { return(Unauthorized()); } if (!HttpContext.Session.GetObjectFromJson <User>("loggedUser").IsAdmin) { return(Unauthorized()); } Movie movie = movieRepo.Get(a => a.Id == id); if (movie == null) { return(NotFound()); } movieRepo.Delete(movie); return(Ok(movie)); }
public void TestDeleteMovieOk() { Movie movie = new Movie() { Name = "Elona Holmes", AgeAllowed = 12, CategoryId = 1, Description = "La herama de Sherlock y Mycroft Holmes", Duration = 2.1, Image = "Mi directorio", }; this.context.Add(movie); this.context.SaveChanges(); var repository = new MovieRepository(this.context); var movieToDelete = repository.Get(1); repository.Delete(movieToDelete); Assert.AreEqual(repository.GetAll().Count(), 0); }
public ActionResult Delete(string id, FormCollection collection) { try { rep.Delete(id); rep.Save(); return(RedirectToAction("Index")); } catch (Exception e) { if (this.HttpContext.IsDebuggingEnabled) { ModelState.AddModelError(string.Empty, e.ToString()); } else { ModelState.AddModelError(string.Empty, "some technical error happened"); } return(View()); } }
public void Execute() { var movieFromRepository = MovieRepository.GetById(Command.Id); if (movieFromRepository != null) { MovieRepository.Delete(movieFromRepository); if (!MovieRepository.SaveChanges()) { Command.WasSuccesful = false; Command.ErrorMessage = "Failed to delete on save"; } else { Command.WasSuccesful = true; } } else { Command.WasSuccesful = false; Command.ErrorMessage = "Movie not found"; } }
public IActionResult DeleteMovie(long id) { moviesRepository.Delete(id); return(NoContent()); }
public void RemoveMovie(int id) { mrep.Delete(mrep.GetByID(id)); mrep.Save(); }
static void Main(string[] args) { MovieRepository movieRepository = new MovieRepository(); Start: // Print All Movies Console.WriteLine("All Movies"); var movies = movieRepository.GetAll(); Print(movies); Retry: // Options Console.WriteLine("Choose the Operation : Delete,Create,Update or GetById; Write Down your Option"); Console.WriteLine("~~~If you want to EXIT write down~~~"); var option = Console.ReadLine().ToLower(); switch (option) { case "create": goto Create; case "delete": goto Delete; case "update": goto Update; case "getbyid": goto GetById; case "exit": goto Exit; default: Console.WriteLine("Unknow Command"); goto Retry; } #region Create Create: Console.WriteLine("Create"); var newMovie = new Movie(); var newDirector = new Director(); // Name Console.WriteLine("Enter Movie Name"); newMovie.Name = Console.ReadLine(); // Rating Console.WriteLine("Enter Rating"); newMovie.Rating = Convert.ToDouble(Console.ReadLine()); // Genre Console.WriteLine("Enter Genre : (Detective - 1, Fantasy - 2, Science_Fiction - 3, " + "Documentary - 4, Action - 5, Crime - 6, Drama - 7, Other - 0)"); Console.WriteLine("Please Enter Number of Genre!"); var genreNum = Convert.ToInt32(Console.ReadLine()); switch (genreNum) { case 1: newMovie.Genre = GenreEnum.Detective; break; case 2: newMovie.Genre = GenreEnum.Fantasy; break; case 3: newMovie.Genre = GenreEnum.Science_Fiction; break; case 4: newMovie.Genre = GenreEnum.Documentary; break; case 5: newMovie.Genre = GenreEnum.Action; break; case 6: newMovie.Genre = GenreEnum.Crime; break; case 7: newMovie.Genre = GenreEnum.Drama; break; default: newMovie.Genre = GenreEnum.Other; break; } // Director Console.WriteLine("Enter Director Name : "); newDirector.FullName = Console.ReadLine(); newMovie.Director = newDirector; movieRepository.Create(newMovie); Console.WriteLine(); goto Start; #endregion #region Delete Delete: Console.WriteLine("Delete"); Console.WriteLine("Enter Objects 'Id' which you want to delete "); var id = Convert.ToInt32(Console.ReadLine()); movieRepository.Delete(id); Console.WriteLine(); goto Start; #endregion #region Update Update: Console.WriteLine("Update"); Console.WriteLine("Select 'Id' which you want to update"); var updateId = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Write Field which you want to update"); EnterFieldAgain: var field = Console.ReadLine().ToLower(); var updateMovie = movies.Where(e => e.Id == updateId).FirstOrDefault(); switch (field) { case "name": Console.WriteLine("Enter New Name : "); updateMovie.Name = Console.ReadLine(); break; case "rating": Console.WriteLine("Enter New Rating : "); updateMovie.Rating = Convert.ToDouble(Console.ReadLine()); break; case "genre": Console.WriteLine("Enter New Genre : "); Console.WriteLine("Choose From Them : (Detective - 1, Fantasy - 2, Science_Fiction - 3, " + "Documentary - 4, Action - 5, Crime - 6, Drama - 7, Other - 0)"); Console.WriteLine("Please Enter Number of Genre!"); var genNum = Convert.ToInt32(Console.ReadLine()); switch (genNum) { case 1: updateMovie.Genre = GenreEnum.Detective; break; case 2: updateMovie.Genre = GenreEnum.Fantasy; break; case 3: updateMovie.Genre = GenreEnum.Science_Fiction; break; case 4: updateMovie.Genre = GenreEnum.Documentary; break; case 5: updateMovie.Genre = GenreEnum.Action; break; case 6: updateMovie.Genre = GenreEnum.Crime; break; case 7: updateMovie.Genre = GenreEnum.Drama; break; default: updateMovie.Genre = GenreEnum.Other; break; } break; case "director": Console.WriteLine("Enter New Director Name : "); updateMovie.Director.FullName = Console.ReadLine(); break; default: Console.WriteLine("Uncknow Field"); goto EnterFieldAgain; } movieRepository.Update(updateMovie); Console.WriteLine(); goto Start; #endregion #region GetById GetById: Console.WriteLine("GetById"); Console.WriteLine("Write down 'Id' which movie info you want "); var getId = Convert.ToInt32(Console.ReadLine()); var getMovie = movieRepository.GetById(getId); Print(getMovie); Console.WriteLine(); goto Start; #endregion Exit: Console.WriteLine("Shutting Down"); }
/// <summary> /// Removes the movie request. /// </summary> /// <param name="requestId">The request identifier.</param> /// <returns></returns> public async Task RemoveMovieRequest(int requestId) { var request = await MovieRepository.GetAll().FirstOrDefaultAsync(x => x.Id == requestId); await MovieRepository.Delete(request); }
// GET: public ActionResult Delete(int id) { movieRepo.Delete(id); return(RedirectToAction("Index", "Home")); }
public int DeleteMovie(int id) { return(movieRepository.Delete(id)); }
private static void ManageMovies(OperationType operationType, object[] args) { switch (operationType) { case OperationType.Create: List <Order> ordersToBeCreated = new List <Order>(); if (args.Length > 2) { int[] ordersIdsToBeCreated = args[2] as int[]; foreach (var item in ordersIdsToBeCreated) { ordersToBeCreated.Add(context.Orders.Find(item)); } } Movie movieToBeCreated = new Movie { Name = args[0].ToString(), Duration = int.Parse(args[1].ToString()), Orders = ordersToBeCreated }; movieRepository.Create(movieToBeCreated); break; case OperationType.Read: int readKey = int.Parse(args[0].ToString()); Movie readMovie = movieRepository.Read(readKey); EventManager.OnMovieShowing(readMovie); break; case OperationType.ReadAll: ICollection <Movie> readMovies = movieRepository.ReadAll(); foreach (var item in readMovies) { EventManager.OnMovieShowing(item); } break; case OperationType.Delete: int deleteKey = int.Parse(args[0].ToString()); movieRepository.Delete(deleteKey); break; case OperationType.Update: List <Order> ordersToBeUpdated = new List <Order>(); if (args.Length > 2) { int[] ordersIdsToBeUpdated = args[3] as int[]; foreach (var item in ordersIdsToBeUpdated) { ordersToBeUpdated.Add(context.Orders.Find(item)); } } Movie moviesToBeUpdated = new Movie() { ID = int.Parse(args[0].ToString()), Name = args[1].ToString(), Duration = int.Parse(args[2].ToString()), Orders = ordersToBeUpdated, }; movieRepository.Update(moviesToBeUpdated); break; case OperationType.Find: string index = args[0].ToString(); ICollection <Movie> moviesFound = movieRepository.Find(index); foreach (var item in moviesFound) { EventManager.OnMovieShowing(item); } break; default: break; } }
public IActionResult Delete(int id) { _movieRepository.Delete(id); return(NoContent()); }
public ActionResult DeleteMovie(int id) { _mvRep.Delete(_mvRep.Find(id)); return(RedirectToAction("MovieList")); }
public void DeleteConfirmed(int id) { repository.Delete(id); }
public void Delete(int id) { movieRepository.Delete(id); }