Ejemplo n.º 1
0
        public static int InserNewMovie()
        {
            var rand = new RandomGenerator();

            CinameNetworkEntities northwindEntities = new CinameNetworkEntities();

            Movy newProduct = new Movy
            {
                Title = rand.GetRandomString(5, 15),
                GenreId = rand.GetRandomInt(1, 1000),
                ReleaseDate = rand.GetRandomDateTime(),
                Director = rand.GetRandomInt(1, 1000),
                Actors = rand.GetRandomInt(1, 100),
                Description = rand.GetRandomString(20, 60),
                CoverLink = rand.GetRandomString(5, 25),
                Subtitles = false,
                DurationMinutes = rand.GetRandomInt(40, 150)
            };

            northwindEntities.Movies.Add(newProduct);
            northwindEntities.SaveChanges();

            return newProduct.MovieId;
        }
        private Movy GetRandomMovie()
        {
            using (var db = new CinameNetworkEntities())
            {
                var genreIds = db.Genres.Select(g => g.GenreId).ToList();
                var countriesIds = db.Countries.Select(c => c.CountryId).ToList();
                var peopleIds = db.People.Select(p => p.PersonId).ToList();
                var people = db.People.ToList();

                var movie = new Movy();
                movie.Title = randomGenerator.GetRandomString(5, 20);
                movie.GenreId = genreIds[randomGenerator.GetRandomInt(0, genreIds.Count - 1)];
                movie.ReleaseDate = randomGenerator.GetRandomDateTime();
                movie.Director = peopleIds[randomGenerator.GetRandomInt(0, peopleIds.Count - 1)];

                var numberOfActors = randomGenerator.GetRandomInt(3, 10);
                for (int i = 0; i < numberOfActors; i++)
                {
                    movie.People.Add(people[randomGenerator.GetRandomInt(0, people.Count - 1)]);
                }

                movie.CountryId = countriesIds[randomGenerator.GetRandomInt(0, countriesIds.Count - 1)];
                movie.Description = randomGenerator.GetRandomString(10, 20);
                movie.Subtitles = false;
                movie.DurationMinutes = randomGenerator.GetRandomInt(5, 200);

                return movie;
            }
        }