Пример #1
0
        public ActionResult Add(AddMovieVM model)
        {
            var selectedGenres = model.Genres.Where(x => x.IsChecked).Select(x => x.ID).ToList();

            MovieManager.Add(model.Title, model.ReleaseDate, model.RunningTimeMinutes, selectedGenres);
            return(RedirectToAction("Index"));
        }
Пример #2
0
        private void AddMovie()
        {
            var result = CheckInputs();

            if (result)
            {
                Movie movie = new Movie
                {
                    GenreId     = GenreId(),
                    DirectorId  = DirectorId(),
                    Name        = textBox2.Text.ToString(),
                    Title       = textBox3.Text.ToString(),
                    Rating      = double.Parse(textBox5.Text.ToString()),
                    ReleaseYear = textBox4.Text.ToString(),
                    MovieLength = Int32.Parse(textBox6.Text.ToString()),
                    dailyPrice  = double.Parse(textBox7.Text.ToString()),
                };
                movieManager.Add(movie);
            }
        }
        public ActionResult Create(MovieViewModel model)
        {
            if (model.File != null)
            {
                var fileInfo = new FileInfo(model.File.FileName);

                model.Poster = fileInfo.Name;

                var fullFileName = System.Web.HttpContext.Current.Server.MapPath("~/assets/images/movie-posters/") + fileInfo.Name;

                if (!System.IO.File.Exists(fullFileName))
                {
                    model.File.SaveAs(fullFileName);
                }
            }

            MovieManager.Add(model);

            return(RedirectToAction("Index"));
        }
Пример #4
0
        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 void Post([FromBody] Movie movie)
 {
     _repo.Add(movie);
 }