Пример #1
0
        List<Movie> CreateTestMovies()
        {
            List<Movie> movies = new List<Movie>();

            for (int i = 0; i < 101; i++)
            {
                Random r = new Random(i);

                Movie tmpMovie = new Movie()
                {
                    movie_id = i,
                    title = "Test Movie " + i.ToString(),
                    year = r.Next(1941, DateTime.Now.Year + 1),
                    length = r.Next(40, 200),
                    director_id = r.Next(4, 20),
                    genre_id = 3,
                    location_id = 1,
                    rating_id = 1
                };

                movies.Add(tmpMovie);
            }

            return movies;
        }
Пример #2
0
        public MovieFormViewModel(Movie movie)
        {
            Movie = movie;

            GenreRepository genreRepo = new GenreRepository();
            LocationRepository locaRepo = new LocationRepository();
            RatingRepository ratingRepo = new RatingRepository();

            Genres = new SelectList(genreRepo.GetAllGenres(), "genre_id", "genre_name", movie.genre_id);
            Locations = new SelectList(locaRepo.GetAllLocations(), "location_id", "location_name", movie.location_id);
            Ratings = new SelectList(ratingRepo.GetAllRatings(), "rating_id", "rating_name", movie.rating_id);
        }
Пример #3
0
        public void Movie_Should_Be_Invalid_When_Props_Incorrect()
        {
            Movie movie = new Movie()
            {
                title = "The Jerk",  // duplicate title
                year = 1894,  // out of range
                length = -5  // also out of range
            };

            bool isValid = movie.IsValid;

            Assert.IsFalse(isValid);
        }
Пример #4
0
        public void Movie_Should_Be_Valid_When_Props_Correct()
        {
            Movie movie = new Movie()
            {
                title = "Test Title",
                year = DateTime.Now.Year,
                length = 100,
                genre_id = 3,
                rating_id = 1,
                director_id = 1,
                location_id = 1
            };

            bool isValid = movie.IsValid;

            Assert.IsTrue(isValid);
        }
Пример #5
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UpdateModel(movie);
                    movieRepo.Add(movie);

                    movieRepo.Save();

                    return RedirectToAction("Details", new { id = movie.movie_id });
                }
                catch
                {
                    ModelState.AddRuleViolations(movie.GetRuleViolations());
                }
            }

            return View(new MovieFormViewModel(movie));
        }
Пример #6
0
 // GET: /Movies/Create/
 public ActionResult Create()
 {
     Movie movie = new Movie();
     return View(new MovieFormViewModel(movie));
 }
Пример #7
0
        // POST: /Movies/MovieSearch/
        public ActionResult MovieSearch(Movie movie)
        {
            string yearRange = Request.Form["Movie.year_range"];
            string lengthRange = Request.Form["Movie.length_range"];

            var movies = movieRepo.Search(movie.title, yearRange, lengthRange, movie.genre_id, movie.rating_id, null, movie.location_id);
            var pagedMovies = new PaginatedList<Movie>(movies, 0, movies.Count());

            return (Request.IsAjaxRequest()) ? View("MovieList", pagedMovies) : View(pagedMovies);
        }
Пример #8
0
 public void Delete(Movie removeMovie)
 {
     movieList.Remove(removeMovie);
 }
Пример #9
0
 public void Add(Movie newMovie)
 {
     movieList.Add(newMovie);
 }
Пример #10
0
 public void Delete(Movie removeMovie)
 {
     db.Movies.DeleteOnSubmit(removeMovie);
 }
Пример #11
0
 public void Add(Movie newMovie)
 {
     db.Movies.InsertOnSubmit(newMovie);
 }