Exemplo n.º 1
0
        public ActionResult CreateOrUpdate(MovieViewModel model)
        {
            if (!ValidateForm(model))
            {
                model.MovieTypeSelectList     = GetMovieTypeSelectListItem();
                model.CulturedMovieSelectList = GetRelatedEntitiesList();

                var genreIds = GetGenreIds(model.Id);
                model.GenreMultiSelectList = GenreMultiSelectList(genreIds);

                var actorIds = GetActorIds(model.Id);
                model.ActorMultiSelectList = ActorMultiSelectList(actorIds);

                CreateNotification(ActionResultType.Failure);
                return(View("CreateOrUpdate", model));
            }

            var movieParams = _movieService.CreateOrUpdate(model);

            _genreService.CreateGenresByIds(model.GenreIds, movieParams.Id);
            _actorService.CreateActorsById(model.ActorIds, movieParams.Id);

            CreateNotification(ActionResultType.Success);

            return(RedirectToAction("Update", new { movieParams.Id }));
        }