Esempio n. 1
0
        public ActionResult Update(MovieViewModel movie)
        {
            if (ModelState.IsValid)
            {
                if (movie != null)
                {
                    var movieToUpdate = context.Movies.Find(movie.Id);

                    if (movieToUpdate != null)
                    {
                        var actorId = Convert.ToInt32(movie.LeadingActorName);
                        if (actorId != 1)
                        {
                            movieToUpdate.Actor = context.Actors.Find(actorId);
                        }

                        var actressId = Convert.ToInt32(movie.LeadingActressName);
                        if (actressId != 1)
                        {
                            movieToUpdate.Actress = context.Actresses.Find(actressId);
                        }

                        var directorId = Convert.ToInt32(movie.DirectorName);
                        movieToUpdate.Director = context.Directors.Find(directorId);

                        var studioId = Convert.ToInt32(movie.StudioName);
                        movieToUpdate.Studio = context.Studios.Find(studioId);

                        if (movieToUpdate.Title != movie.Title)
                        {
                            movieToUpdate.Title = movie.Title;
                        }

                        if (movieToUpdate.Year != movie.Year)
                        {
                            movieToUpdate.Year = movie.Year;
                        }

                        context.SaveChanges();
                        return Content("");
                    }
                    else
                    {
                        throw new ArgumentException(string.Format("Movie with id={0} doesn't exist.", movie.Id));
                    }
                }
                else
                {
                    throw new ArgumentNullException("movie");
                }
            }

            return PartialView("_Edit", movie);
        }
Esempio n. 2
0
 public ActionResult ConfirmDelete(MovieViewModel movie)
 {
     var movieToDelete = context.Movies.Find(movie.Id);
     if (movieToDelete != null)
     {
         context.Movies.Remove(movieToDelete);
         context.SaveChanges();
         return Content("");
     }
     else
     {
         throw new ArgumentException("No movie specified.");
     }
 }
Esempio n. 3
0
        public ActionResult Edit(MovieViewModel movie)
        {
            CreateDropDownData(movie);

            return PartialView("_Edit", movie);
        }
Esempio n. 4
0
        private void CreateDropDownData(MovieViewModel movie)
        {
            movie.Actresses = context.Actresses.ToList().Select(x => new SelectListItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });

            movie.Actors = context.Actors.ToList().Select(x => new SelectListItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });

            movie.Studios = context.Studios.ToList().Select(x => new SelectListItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });

            movie.Directors = context.Directors.ToList().Select(x => new SelectListItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });
        }
Esempio n. 5
0
        public ActionResult Create(MovieViewModel movie)
        {
            if (movie != null)
            {
                var newMovie = new Movie
                {
                    Title = movie.Title,
                    Year = movie.Year,
                };

                var actorId = Convert.ToInt32(movie.LeadingActorName);
                if (actorId != 1)
                {
                    newMovie.Actor = context.Actors.Find(actorId);
                }

                var actressId = Convert.ToInt32(movie.LeadingActressName);
                if (actressId != 1)
                {
                    newMovie.Actor = context.Actors.Find(actressId);
                }

                var directorId = Convert.ToInt32(movie.DirectorName);
                newMovie.Director = context.Directors.Find(directorId);

                var studioId = Convert.ToInt32(movie.StudioName);
                newMovie.Studio = context.Studios.Find(studioId);

                context.Movies.Add(newMovie);
                context.SaveChanges();
            }

            return Content("");
        }
Esempio n. 6
0
        public ActionResult Create()
        {
            var movie = new MovieViewModel();
            CreateDropDownData(movie);

            return PartialView("_Create", movie);
        }
Esempio n. 7
0
 public ActionResult Delete(MovieViewModel movie)
 {
     return PartialView("_Delete", movie);
 }
Esempio n. 8
0
 public ActionResult Search(string input, string GenreName, string sortValue)
 {
     MovieViewModel SWM = new MovieViewModel(sortValue);
     SWM.SetSortedLists(input, GenreName);
     return View("SearchResult", SWM);
 }
Esempio n. 9
0
 // GET: Movies
 public ActionResult Index(string sortValue)
 {
     MovieViewModel model = new MovieViewModel(sortValue);
     return View(model);
 }