Exemple #1
0
        public async Task <IActionResult> Edit(ActorEditModel actorEditModel)
        {
            if (ModelState.IsValid)
            {
                Actor foundActor = await _actors.GetById(actorEditModel.Id);

                if (foundActor != null)
                {
                    foundActor.Name = actorEditModel.Name;

                    foreach (AssignedMovies assignedMovie in actorEditModel.AssignedMovies)
                    {
                        if (assignedMovie.Assigned)
                        {
                            _actors.AddMovie(foundActor, assignedMovie.Id);
                        }

                        else if (foundActor.FilmCasts.Select(filmCast => filmCast.MovieId).ToList().Contains(assignedMovie.Id))
                        {
                            _actors.RemoveMovie(foundActor, assignedMovie.Id);
                        }
                    }
                    _actors.Save();
                    ModelState.Clear();
                    return(RedirectToAction($"Detail/{foundActor.Id}"));
                }
            }
            return(NotFound());
        }