public ActionResult Create(MovieViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                using (manager = new MovieManager())
                {
                    Movie movie = new Movie();
                    movie.Cost        = viewModel.Movie.Cost;
                    movie.Description = viewModel.Movie.Description;
                    movie.Title       = viewModel.Movie.Title;
                    movie.Director    = new Director {
                        Id = viewModel.SelectedDirectorId
                    };
                    movie.Format = new Format {
                        Id = viewModel.SelectedFormatId
                    };
                    movie.Rating = new Rating {
                        Id = viewModel.SelectedRatingId
                    };

                    if (viewModel.File != null)
                    {
                        movie.ImagePath = viewModel.File.FileName;
                        string saveTarget = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(viewModel.File.FileName));
                        if (!System.IO.File.Exists(saveTarget))
                        {
                            viewModel.File.SaveAs(saveTarget);
                        }
                    }
                    int id = manager.Add(movie);
                    manager.AddGenres(id, viewModel.CurrentGenres);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(View(viewModel));
            }
        }
        public ActionResult Edit(MovieViewModel vm)
        {
            if (ModelState.IsValid)
            {
                using (manager = new MovieManager())
                {
                    Movie movie = manager.GetById(vm.Movie.Id);
                    movie.Cost        = vm.Movie.Cost;
                    movie.Description = vm.Movie.Description;
                    movie.Title       = vm.Movie.Title;
                    movie.Format      = new Format {
                        Id = vm.SelectedFormatId
                    };
                    movie.Director = new Director {
                        Id = vm.SelectedDirectorId
                    };
                    movie.Rating = new Rating {
                        Id = vm.SelectedRatingId
                    };
                    manager.Update(movie);
                    manager.AddGenres(vm.Movie.Id, vm.CurrentGenres);

                    if (vm.File != null)
                    {
                        movie.ImagePath = vm.File.FileName;
                        string saveTarget = Path.Combine(Server.MapPath("/images"), Path.GetFileName(vm.File.FileName));
                        if (!System.IO.File.Exists(saveTarget))
                        {
                            vm.File.SaveAs(saveTarget);
                        }
                    }

                    return(RedirectToAction("Index"));
                }
            }
            return(View(vm));
        }