Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Name,ReleaseDate,Plot,ProducerId")] Movie movie)

        {
            ModelState.Remove("Id");
            if (ModelState.IsValid)
            {
                try
                {
                    String[] actorIds = Request["Actors"].Split(',');
                    movie.MoviePosterPath = SaveFile(Request.Files[0]);
                    var actorsToAdd = _movieDal.ActorRepository.GetActors(actorIds.Select(e => Convert.ToInt32(e)).ToArray());
                    foreach (var actor in actorsToAdd)
                    {
                        movie.Actors.Add(actor);
                    }

                    _movieDal.MovieRepository.AddMovie(movie);

                    _movieDal.Save();

                    return(RedirectToAction("Index"));
                }
                catch (Exception)
                {
                    return(Content("Error Occured"));
                }
            }

            ViewBag.ProducerId = new SelectList(_movieDal.ProducerRepository.GetProducers(), "Id", "Name", movie.ProducerId);
            ViewBag.Actors     = _movieDal.ActorRepository.GetActors();
            return(View("Create"));
        }