public ActionResult AddActor([Bind(Include = "PeliculaId, ActorId")] ViewModel.ActorPelicula actPeli) { Pelicula pelicula = db.Peliculas.Find(actPeli.PeliculaId); Actor act = db.Actors.Find(actPeli.ActorId); if (pelicula == null || act == null) { return(HttpNotFound()); } if (ModelState.IsValid) { pelicula.Actores.Add(act); db.Entry(pelicula).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = actPeli.PeliculaId })); } var ids = pelicula.Actores.Select(x => x.Id).ToArray(); var query = db.Actors .Where(x => !ids.Contains(x.Id)) .Select(x => new { x.Id, Text = x.Nombre + " " + x.Apellidos }).ToList(); ViewBag.ActorId = new SelectList(query, "Id", "Text", actPeli.ActorId); return(View(actPeli)); }
public ActionResult QuitActor([Bind(Include = "PeliculaId, ActorId")] ViewModel.ActorPelicula actPeli) { Pelicula pelicula = db.Peliculas.Find(actPeli.PeliculaId); Actor act = db.Actors.Find(actPeli.ActorId); pelicula.Actores.Remove(act); db.SaveChanges(); return(RedirectToAction("Details", new { id = actPeli.PeliculaId })); }