public async Task <ActionResult> EditMovie(int id, UpdateMovieDto updateMovie) { var movieToUpdate = await context.Movies.Include(ma => ma.MovieActors).SingleOrDefaultAsync(movie => movie.Id == id); movieToUpdate.MovieName = updateMovie.Name; movieToUpdate.Year = updateMovie.Year; movieToUpdate.Genre = updateMovie.Genre; foreach (var actor in movieToUpdate.MovieActors) { if (!updateMovie.ActorIds.Contains(actor.ActorId)) { context.Remove(actor); } } foreach (var actorId in updateMovie.ActorIds) { if (!movieToUpdate.MovieActors.Any(a => a.ActorId == actorId)) { movieToUpdate.MovieActors.Add(new MovieActor { ActorId = actorId, MovieId = id }); } } await context.SaveChangesAsync(); return(Ok()); }
public IActionResult DeleteMovie(int id) { var movieToUpdate = (from c in _movieContext.Movies where c.MovieId == id select c).FirstOrDefault(); _movieContext.Remove(movieToUpdate); //delete the movie object _movieContext.SaveChanges(); //save the changes return(RedirectToAction("Index")); }
public void DeleteMovie(Movie movieToDelete) { if (movieToDelete == null) { throw new ArgumentNullException(nameof(movieToDelete)); } _context.Remove(movieToDelete); }
public async Task <bool> Delete(int id) { Task <Movie> mvTask = _dbContext.Movies.FirstOrDefaultAsync(p => p.MovieID == id); Movie mv = mvTask.Result; if (mv == null) { return(false); } _dbContext.Remove(mv); await _dbContext.SaveChangesAsync(); return(true); }
public void Delete(int id) { _listaPeliculas.Remove(this.Find(id)); _listaPeliculas.SaveChanges(); }
public void DeleteMovie(Guid movieId) { var movie = _context.Movies.Find(movieId); _context.Remove(movie); }