Ejemplo n.º 1
0
        public ActionResult MovieEdit(MovieEditViewModel viewModel, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                int?directorId = null;
                if (int.TryParse(collection[CreateFilmViewModel.DirectorCollectionKey], out var dt))
                {
                    directorId = dt;
                }
                _movieService.EditMovie(FilmViewerMapper.Mapper.Map <MovieDetailsDto>(viewModel),
                                        ManagerHelper.CategoryCommaCollectionRefactor(collection[CreateFilmViewModel.ActorCollectionKey]),
                                        directorId,
                                        ManagerHelper.CategoryCommaCollectionRefactor(collection[CreateFilmViewModel.MetadataCollectionKey]),
                                        ManagerHelper.CategoryCommaCollectionRefactor(collection[CreateFilmViewModel.CategoryCollectionKey])
                                        );
                TempData[UserMessages.UserMessage] = new MessageViewModel()
                {
                    CssClass = "alert-success",
                    Message  = Resources.MovieEditedSuccesfully
                };

                return(RedirectToAction("MovieView"));
            }
            return(RedirectToAction("MovieEdit", new { id = viewModel.MovieId }));
        }
Ejemplo n.º 2
0
        public IActionResult Edit(int movieId)
        {
            Movie movieFromDb = _movieService.Get(movieId);
            List <MovieGenreListViewModel> genreList = new List <MovieGenreListViewModel>();
            List <int> genresInMovie = _genreService.GetGenresByMovieId(movieId).Select(g => g.Id).ToList();

            foreach (var genre in _genreService.Get())
            {
                genreList.Add(new MovieGenreListViewModel()
                {
                    Naam = genre.Naam, Checked = genresInMovie.Contains(genre.Id)
                });
            }
            ;

            string regisseur = _regisseurService.GetRegisseursByMovieId(movieId).Select(r => r.Naam).ToString();

            MovieEditViewModel vm = new MovieEditViewModel {
                Id           = movieFromDb.Id,
                Beschrijving = movieFromDb.Beschrijving,
                GenreList    = genreList,
                Regisseurs   = regisseur,
                Speelduur    = movieFromDb.Speelduur,
                Titel        = movieFromDb.Titel
            };

            return(View(vm));
        }
        // GET: Movies/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movie.FindAsync(id);

            if (movie == null)
            {
                return(NotFound());
            }
            ViewData["GenreID"] = new SelectList(_context.Genre, "GenreID", "Description", movie.GenreID);

            MovieEditViewModel m = new MovieEditViewModel
            {
                MovieId     = movie.MovieId,
                Title       = movie.Title,
                ReleaseDate = movie.ReleaseDate,
                Price       = movie.Price,
                GenreID     = movie.GenreID
            };

            return(View(m));
        }
        public async Task CheckEditingMovieWithMissingMovie()
        {
            this.SeedDatabase();
            await this.SeedMovies();

            var model = new MovieEditViewModel
            {
                Id             = 3,
                Name           = this.firstMovie.Name,
                DateOfRelease  = this.firstMovie.DateOfRelease,
                Resolution     = this.firstMovie.Resolution,
                Rating         = this.firstMovie.Rating,
                Description    = this.firstMovie.Description,
                Language       = this.firstMovie.Language,
                CinemaCategory = this.firstMovie.CinemaCategory.ToString(),
                TrailerPath    = this.firstMovie.TrailerPath,
                CoverImage     = null,
                Wallpaper      = null,
                IMDBLink       = this.firstMovie.IMDBLink,
                Length         = this.firstMovie.Length,
                DirectorId     = this.firstMovie.DirectorId,
                SelectedGenres = new List <int> {
                    1,
                },
                SelectedCountries = new List <int> {
                    1,
                },
            };

            var exception = await Assert
                            .ThrowsAsync <NullReferenceException>(async() => await this.moviesService.EditAsync(model));

            Assert.Equal(string.Format(ExceptionMessages.MovieNotFound, model.Id), exception.Message);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, MovieEditViewModel movieEditViewModel)
        {
            if (id != movieEditViewModel.Movie.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var movie = movieEditViewModel.Movie;
                try
                {
                    movie.Genre = await _context.Genres.FindAsync(movieEditViewModel.GenreIdSelected);

                    _context.Update(movie);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieExists(movie.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieEditViewModel));
        }
Ejemplo n.º 6
0
        // GET: Movies/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movie.FindAsync(id);

            if (movie == null)
            {
                return(NotFound());
            }

            // ideally this should have a fk in movie
            // ill try to work back on this if i have some time left
            // but this should do for now (i hope)
            var genres = from g in _context.Genre
                         select g.Name;

            var movieEditVM = new MovieEditViewModel
            {
                Genres = new SelectList(await genres.ToListAsync()),
                Movie  = movie
            };

            return(View(movieEditVM));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> MovieEdit(MovieEditViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View(model));
            }
            Movie movie = new Movie()
            {
                Id           = model.Id,
                Title        = model.Title,
                Beschrijving = model.Beschrijving,

                ReleaseDate = model.ReleaseDate,
            };

            using (var memoryStream = new MemoryStream())
            {
                await model.Foto.CopyToAsync(memoryStream);

                movie.Foto = memoryStream.ToArray();
            }
            _appContext.Movies.Update(movie);
            _appContext.SaveChanges();
            return(RedirectToAction("MovieMain", "Movie"));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(int id)
        {
            //Movies table
            var movie = new Movie();

            movie.Id       = 1;
            movie.Title    = "Star Wars";
            movie.Director = "George Lucas";

            //Categories table
            var categories = new List <Category>
            {
                new Category {
                    Id = 1, Name = "Action"
                },
                new Category {
                    Id = 2, Name = "Horror"
                }
            };

            var vm = new MovieEditViewModel
            {
                Movie      = movie,
                Categories = categories
            };

            return(View(vm));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(Guid id, MovieEditViewModel movieEditViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _movieService.UpdateMovie(id, movieEditViewModel);

                    _flashMessage.Confirmation("Movie has been updated.");

                    return(RedirectToAction(nameof(Show), new { id }));
                }
                catch (MovieNotFoundException)
                {
                    return(NotFound());
                }
                catch (AccessDeniedException)
                {
                    return(Forbid());
                }
            }

            movieEditViewModel = await _movieService.LoadGenresAndPersonsToEditViewModel(movieEditViewModel);

            return(View(movieEditViewModel));
        }
Ejemplo n.º 10
0
        public void ShouldReturnDefaultViewModelWithNoErrorWhenModelIsValid()
        {
            // Arrange
            var success      = new Result(ResultType.Success);
            var moviesSvMock = new Mock <IMoviesService>();

            moviesSvMock.Setup(x => x.UpdateMovie(It.IsAny <Movies>())).Returns(success);
            var fakeMovie       = new MovieEditViewModel();
            var sut             = new MoviesController(moviesSvMock.Object);
            var fakeHttpContext = new Mock <HttpContextBase>();

            sut.ControllerContext = new ControllerContext
            {
                Controller  = sut,
                HttpContext = fakeHttpContext.Object
            };
            var mapper = new AutoMapperConfig();

            mapper.Execute(Assembly.GetExecutingAssembly());
            Mapper.Initialize(cfg =>
                              cfg.CreateMap <MovieEditViewModel, Movies>());


            // Act & Assert
            sut
            .WithCallTo(c => c.Edit(fakeMovie))
            .ShouldRenderDefaultView()
            .WithModel <MovieEditViewModel>(x => Assert.AreEqual(x.Result.ResulType, ResultType.Success));
        }
Ejemplo n.º 11
0
        public ActionResult Save(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieEditViewModel
                {
                    Movie            = movie,
                    MovieRatingCodes = _context.MovieRatingCodes.ToList(),
                    MovieGenreCodes  = _context.MovieGenreCodes.ToList()
                };
                return(View("Edit", viewModel));
            }

            if (movie.Id == 0)
            {
                _context.Movies.Add(movie);
            }
            else
            {
                var movieInDb = _context.Movies.Single(m => m.Id == movie.Id);
                movieInDb.MovieName         = movie.MovieName;
                movieInDb.GenreId           = movie.GenreId;
                movieInDb.ReleaseDate       = movie.ReleaseDate;
                movieInDb.Runtime           = movie.Runtime;
                movieInDb.MovieDescription  = movie.MovieDescription;
                movieInDb.MoviePlotSummary  = movie.MoviePlotSummary;
                movieInDb.MovieRatingCodeId = movie.MovieRatingCodeId;
                movieInDb.GenreId           = movie.GenreId;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Movies"));
        }
Ejemplo n.º 12
0
        // GET: Movies/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movie.FindAsync(id);

            if (movie == null)
            {
                return(NotFound());
            }



            IQueryable <string> genreQuery = from g in _context.Genre
                                             select g.Title;

            var movieEditVM = new MovieEditViewModel
            {
                Genres = new SelectList(await genreQuery.Distinct().ToListAsync()),
                Movie  = movie
            };

            return(View(movieEditVM));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Edit(int id, MovieEditViewModel vm)
        {
            if (!TryValidateModel(vm))
            {
                return(View(vm));
            }

            Movie domainMovie = await _movieDbContext.Movies.Include(m => m.MovieTags).FirstOrDefaultAsync(m => m.Id == id);

            _movieDbContext.MovieTags.RemoveRange(domainMovie.MovieTags);

            domainMovie.Title       = vm.Title;
            domainMovie.Description = vm.Description;
            domainMovie.Genre       = vm.Genre;
            domainMovie.ReleaseDate = vm.ReleaseDate;
            domainMovie.MovieTags   = vm.SelectedTags.Select(tagId => new MovieTag()
            {
                TagId = tagId
            }).ToList();

            _movieDbContext.Update(domainMovie);

            await _movieDbContext.SaveChangesAsync();

            return(RedirectToAction("Detail", new { Id = id }));
        }
Ejemplo n.º 14
0
        public ActionResult Create(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new MovieEditViewModel(movie)
                {
                    Genres = _context.Genres.ToList()
                };
                return(View("MovieForm", viewModel));
            }

            if (movie.Id == 0)
            {
                movie.NumberAvailable = movie.NumberInStock;
                _context.Movies.Add(movie);
            }
            else
            {
                var movieInDb = _context.Movies.Single(c => c.Id == movie.Id);
                movieInDb.Name                = movie.Name;
                movieInDb.GenreId             = movie.GenreId;
                movieInDb.ReleaseDate         = movie.ReleaseDate;
                movieInDb.DateAddedToDatabase = DateTime.Now;
                movieInDb.NumberInStock       = movie.NumberInStock;
            }

            _context.SaveChanges();
            return(RedirectToAction("ViewMovies", "Movies"));
        }
        // GET: Admin/Movies/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Movie movie = db.Movies.Find(id);

            if (movie == null)
            {
                return(HttpNotFound());
            }
            var vm = new MovieEditViewModel
            {
                Cast          = movie.Cast,
                Description   = movie.Description,
                Director      = movie.Director,
                Duration      = movie.Duration,
                PublishedDate = movie.PublishedDate,
                Title         = movie.Title,
                PhotoPath     = movie.PosterPhotoPath,
                IsActive      = movie.IsActive
            };

            return(View(vm));
        }
        public async Task <IActionResult> Edit(MovieEditViewModel movieEditViewModel)
        {
            if (!this.ModelState.IsValid)
            {
                var directors = await this.directorsService
                                .GetAllDirectorsAsync <DirectorDetailsViewModel>();

                var genres = await this.genresService
                             .GetAllGenresAsync <GenreDetailsViewModel>();

                var countries = await this.countriesService
                                .GetAllCountriesAsync <CountryDetailsViewModel>();

                var movieGenres = await this.moviesService
                                  .GetAllMovieGenresAsync <MovieGenreViewModel>();

                var movieCountries = await this.moviesService
                                     .GetAllMovieCountriesAsync <MovieCountryViewModel>();

                movieEditViewModel.Directors      = directors;
                movieEditViewModel.Genres         = genres;
                movieEditViewModel.Countries      = countries;
                movieEditViewModel.MovieGenres    = movieGenres;
                movieEditViewModel.MovieCountries = movieCountries;

                return(this.View(movieEditViewModel));
            }

            await this.moviesService.EditAsync(movieEditViewModel);

            return(this.RedirectToAction("GetAll", "Movies", new { area = "Administration" }));
        }
Ejemplo n.º 17
0
        public IActionResult Edit(int id)
        {
            var movie = this.moviesService.GetById <MovieEditViewModel>(id);

            var viewModel = new MovieEditViewModel
            {
                IMDBLink    = movie.IMDBLink,
                Language    = movie.Language,
                Length      = movie.Length,
                TrailerLink = movie.TrailerLink,
                Name        = movie.Name,
                Rating      = movie.Rating,
                Summary     = movie.Summary,
                ReleaseDate = movie.ReleaseDate,
                PosterUrl   = movie.PosterUrl,
                Actors      = this.actorsService.GetAll <MovieActorsEditInputModel>(),
                Genres      = this.genresService.GetAll <MovieGenresEditInputModel>(),
                Directors   = this.directorsService.GetAll <MovieDirectorEditInputModel>(),
            };

            if (viewModel == null)
            {
                return(this.NotFound());
            }

            return(this.View(viewModel));
        }
Ejemplo n.º 18
0
        // GET: Movies/Create
        public IActionResult Create()
        {
            var movieGenreView = new MovieEditViewModel
            {
                Genres = _context.Genres.ToList().Select(g => new SelectListItem(g.Name, g.ID.ToString())),
                Movie  = new Movie()
            };

            return(View(movieGenreView));
        }
        public IActionResult EditMovie(MovieEditViewModel movieEditViewModel)
        {
            movieEditViewModel.Movie.CategoryId = movieEditViewModel.CategoryId;

            if (ModelState.IsValid)
            {
                _movieRepository.UpdateMovie(movieEditViewModel.Movie);
                return(RedirectToAction("Index"));
            }
            return(View(movieEditViewModel));
        }
        public IActionResult AddMovie(MovieEditViewModel movieEditViewModel)
        {
            //basic validation
            if (ModelState.IsValid)
            {
                _movieRepository.CreateMovie(movieEditViewModel.Movie);
                return(RedirectToAction("Index"));
            }

            return(View(movieEditViewModel));
        }
Ejemplo n.º 21
0
        public void OnGet(int id)
        {
            var movie = _movieService.GetById(id);

            Movie = new MovieEditViewModel()
            {
                Id         = movie.Id,
                Name       = movie.Name,
                TrySeconds = movie.TrySeconds
            };
        }
Ejemplo n.º 22
0
        public ActionResult New()
        {
            var genre = _context.Genres.ToList();

            var viewModel = new MovieEditViewModel
            {
                Genres = genre
            };

            return(View("MovieForm", viewModel));
        }
 public ActionResult EditMovie(MovieEditViewModel viewModel)
 {
     db.Configuration.ProxyCreationEnabled = false;
     if (ModelState.IsValid)
     {
         var movie = db.Movies.FirstOrDefault(m => m.Id == viewModel.Id);
         if (movie == null)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             db.Entry(movie).Collection(m => m.Actors).Load();
             movie.Name        = viewModel.Name;
             movie.ReleaseDate = viewModel.ReleaseDate;
             movie.ProducerId  = viewModel.ProducerId;
             foreach (var actor in viewModel.Actors)
             {
                 if (actor.Assigned)
                 {
                     if (!movie.Actors.Any(a => a.Id == actor.ActorId))
                     {
                         var toAddActor = db.Actors.FirstOrDefault(a => a.Id == actor.ActorId);
                         movie.Actors.Add(toAddActor);
                     }
                 }
                 else
                 {
                     var removeActor = movie.Actors.SingleOrDefault(a => a.Id == actor.ActorId);
                     if (removeActor != null)
                     {
                         movie.Actors.Remove(removeActor);
                     }
                 }
             }
             //code to edit image
             if (viewModel.ImageFile != null)
             {
                 string fileName  = Path.GetFileNameWithoutExtension(viewModel.ImageFile.FileName);
                 string extension = Path.GetExtension(viewModel.ImageFile.FileName);
                 fileName            = fileName + DateTime.Now.ToString("yymmssfff") + extension;//to avoid duplicacy in file name
                 viewModel.ImagePath = "~/Images/" + fileName;
                 fileName            = Path.Combine(Server.MapPath("~/Images/"), fileName);
                 viewModel.ImageFile.SaveAs(fileName);
                 movie.Photo = viewModel.ImagePath;
             }
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.ProducerId = new SelectList(db.Producers, "ProducerId", "ProducerId");
     return(View());
 }
        public async Task CheckIfEditingMovieWorksCorrectlyWhenImagesStaysTheSame()
        {
            this.SeedDatabase();
            await this.SeedMovies();

            var newDirector = new Director
            {
                FirstName = "Pesho",
                LastName  = "Petrov",
            };

            await this.directorsRepository.AddAsync(newDirector);

            await this.directorsRepository.SaveChangesAsync();

            var movieEditViewModel = new MovieEditViewModel
            {
                Id             = this.firstMovie.Id,
                Name           = "Brothers and sisters",
                DateOfRelease  = DateTime.UtcNow.AddDays(1),
                Resolution     = "SD",
                Rating         = 7.50m,
                Description    = "Changed Test description",
                Language       = "USA",
                CinemaCategory = CinemaCategory.C.ToString(),
                TrailerPath    = "Changed Test trailer path",
                CoverImage     = null,
                Wallpaper      = null,
                IMDBLink       = "Changed Test imdb link",
                Length         = 110,
                DirectorId     = 2,
                SelectedGenres = new List <int> {
                    1,
                },
                SelectedCountries = new List <int> {
                    1,
                },
            };

            await this.moviesService.EditAsync(movieEditViewModel);

            Assert.Equal(movieEditViewModel.Id, this.firstMovie.Id);
            Assert.Equal(movieEditViewModel.Name, this.firstMovie.Name);
            Assert.Equal(movieEditViewModel.DateOfRelease, this.firstMovie.DateOfRelease);
            Assert.Equal(movieEditViewModel.Resolution, this.firstMovie.Resolution);
            Assert.Equal(movieEditViewModel.Rating, this.firstMovie.Rating);
            Assert.Equal(movieEditViewModel.Description, this.firstMovie.Description);
            Assert.Equal(movieEditViewModel.Language, this.firstMovie.Language);
            Assert.Equal(movieEditViewModel.CinemaCategory, this.firstMovie.CinemaCategory.ToString());
            Assert.Equal(movieEditViewModel.TrailerPath, this.firstMovie.TrailerPath);
            Assert.Equal(movieEditViewModel.IMDBLink, this.firstMovie.IMDBLink);
            Assert.Equal(movieEditViewModel.Length, this.firstMovie.Length);
        }
Ejemplo n.º 25
0
        // GET: Movies/Create
        public async Task <IActionResult> CreateAsync()
        {
            IQueryable <string> genreQuery = from g in _context.Genre
                                             select g.Title;

            var movieEditVM = new MovieEditViewModel
            {
                Genres = new SelectList(await genreQuery.Distinct().ToListAsync())
            };

            return(View(movieEditVM));
        }
Ejemplo n.º 26
0
        public IActionResult Edit(int id, MovieEditViewModel ViewModel)
        {
            Movie movie = new Movie()
            {
                Title       = ViewModel.Title,
                Description = ViewModel.Description,
                ReleaseDate = ViewModel.ReleaseDate,
                Genre       = ViewModel.Genre
            };

            _movieDatabase.Update(id, movie);
            return(RedirectToAction("Detail", new { Id = id }));
        }
Ejemplo n.º 27
0
        public IActionResult Edit(MovieEditViewModel model, int movieId)
        {
            Movie movieToEdit = new Movie
            {
                Beschrijving = model.Beschrijving,
                Titel        = model.Titel,
                Speelduur    = model.Speelduur
            };

            _movieService.Edit(model.Id, movieToEdit);

            return(RedirectToAction("Details", new { movieId }));
        }
Ejemplo n.º 28
0
        public ActionResult Edit(int id)
        {
            var movie = _context.Movies.SingleOrDefault(c => c.Id == id) ?? new Movie();

            var viewModel = new MovieEditViewModel
            {
                Movie            = movie,
                MovieRatingCodes = _context.MovieRatingCodes.ToList(),
                MovieGenreCodes  = _context.MovieGenreCodes.ToList()
            };

            return(View("Edit", viewModel));
        }
Ejemplo n.º 29
0
        public IActionResult Edit(int id)
        {
            Movie movieFromDb     = _movieDatabase.GetMovie(id);
            MovieEditViewModel vm = new MovieEditViewModel()
            {
                Title       = movieFromDb.Title,
                Description = movieFromDb.Description,
                Releasedate = movieFromDb.Releasedate,
                Genre       = movieFromDb.Genre
            };

            return(View(vm));
        }
Ejemplo n.º 30
0
        public ViewResult Edit(int id)
        {
            Movie movie = _movieRepository.GetMovie(id);
            MovieEditViewModel movieEditViewModel = new MovieEditViewModel()
            {
                Id                = movie.Id,
                Name              = movie.Name,
                MovieInfo         = movie.MovieInfo,
                ReleseDate        = movie.DateTime,
                ExistingPhotoPath = movie.photopath
            };

            return(View(movieEditViewModel));
        }