Пример #1
0
        public async Task <IActionResult> Create(MovieCreateVM viewModel)
        {
            var genres = context.GetAllGenres();

            viewModel.Genres = context.GetSelectedListItem(genres);

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            int id = context.AddMovie(viewModel);

            var uploads = Path.Combine(hostingEnvironment.WebRootPath, "img");
            var file    = viewModel.Image;

            if (file.Length > 0)
            {
                var filePath = Path.Combine(uploads, $"{id}{Path.GetExtension(file.FileName)}");
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(fileStream);
                }
            }

            return(RedirectToAction(nameof(MoviesController.Display)));
        }
        public IActionResult Create(MovieCreateVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            context.AddMovie(viewModel);
            return(RedirectToAction(nameof(MoviesController.Index)));
        }
Пример #3
0
        public IActionResult Create()
        {
            var genres = context.GetAllGenres();

            var model = new MovieCreateVM();

            model.Genres = context.GetSelectedListItem(genres);

            return(View(model));
        }
        public void AddMovie(MovieCreateVM viewModel)
        {
            var movieToAdd = new Movie
            {
                Title  = viewModel.Title,
                Length = viewModel.Length,
                Genre  = viewModel.Genre,
            };

            Movie.Add(movieToAdd);
            SaveChanges();
        }
Пример #5
0
        public IActionResult Create(MovieCreateVM viewModel)
        {
            var genres = context.GetAllGenres();

            viewModel.Genres = context.GetSelectedListItem(genres);

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            context.AddMovie(viewModel);
            return(RedirectToAction(nameof(MoviesController.Index)));
        }
        public int AddMovie(MovieCreateVM viewModel)
        {
            var movieToAdd = new Movie
            {
                Title   = viewModel.Title,
                Length  = viewModel.Length,
                Genre   = viewModel.Genre,
                About   = viewModel.About,
                Trailer = viewModel.Trailer,
            };


            Movie.Add(movieToAdd);
            SaveChanges();
            return(movieToAdd.Id);
        }