Ejemplo n.º 1
0
 static void Main()
 {
     //set database
     Database.SetInitializer(new MigrateDatabaseToLatestVersion<MoviesEntities, Configuration>());
     var context = new MoviesEntities();
     var moviesCount = context.Movies.Count();
 }
Ejemplo n.º 2
0
        private static void MoviesAndRatings()
        {
            Console.WriteLine();
            using (MoviesEntities ctx = new MoviesEntities())
            {
                var movies = from m in ctx.Movies join g in ctx.Genres on m.GenreID equals g.GenreID select new {Rating = m.Rating, Title = m.Title, mGenre = g.TypeOfGenre, Length = m.LengthInMinutes, Desc = m.Description, Release = m.ReleaseDate, Dir = m.Director};

                foreach (var m in movies)
                {
                    Console.WriteLine("{0}", m.Title);
                    Console.WriteLine(new String('-', 30));
                    Console.WriteLine("Relased:{0} Director:{1} Genre:{2} Rating:{3} Length:{4} min", m.Release, m.Dir, m.mGenre, m.Rating, m.Length);
                    Console.WriteLine();
                    Console.WriteLine("Enter 1 to read a description or any key to continue.");
                    string input = Console.ReadLine();
                    if (input == "1")
                        Console.WriteLine("{0}", m.Desc);
                    Console.WriteLine();
                    Console.WriteLine("Enter 0 to return to Menu or press enter to see next movie.");
                    input = Console.ReadLine();
                    if (input == "0")
                        return;
                    //Console.ReadKey();
                }
            }
        }
Ejemplo n.º 3
0
        static void Main()
        {
            var context = new MoviesEntities();

            //1.	Adult Movies
            //Export all adult movies. Order them by title and by ratings received as secondary criteria.
            //Select each movie's title and the number of ratings received.

            var adultMovies = context.Movies
                .Where(m => m.AgeRestriction == AgeRestriction.Adult)
                .OrderBy(m => m.Title)
                .ThenByDescending(m => m.Ratings.Count)
                .Select(m => new
                {
                    title = m.Title,
                    ratingsGiven = m.Ratings.Count
                });

            string adultMoviesJson = JsonConvert.SerializeObject(adultMovies, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText("../../adult-movies.json", adultMoviesJson);

            // Query 2.Rated Movies by User:
            var ratedMoviesByUser = context.Users
                .Where(u => u.Username == "jmeyery")
                .Select(u => new
                {
                    username = u.Username,
                    ratedMovies = u.Ratings
                        .OrderBy(r => r.Movie.Title)
                        .Select(r => new
                        {
                            title = r.Movie.Title,
                            userRating = r.Stars,
                            averageRating = r.Movie.Ratings.Average(rStars => rStars.Stars)
                        })
                });
            string ratedMoviesByUserJson = JsonConvert.SerializeObject(ratedMoviesByUser, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText("../../rated-movies-by-jmeyery.json", ratedMoviesByUserJson);

            //// Query 3.Top 10 Favourite Movies:
            var favouriteMovies = context.Movies
                .Where(m => m.AgeRestriction == AgeRestriction.Teen)
                .OrderByDescending(m => m.UsersThatMovieIsFavourite.Count)
                .ThenBy(m => m.Title)
                .Take(10)
                .Select(m => new
                {
                    isbn = m.Isbn,
                    title = m.Title,
                    favouritedBy = m.UsersThatMovieIsFavourite.Select(u => u.Username)
                });

            string favouriteMoviesJson = JsonConvert.SerializeObject(favouriteMovies, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText("../../top-10-favourite-movies.json", favouriteMoviesJson);
        }
        public static void Main()
        {
            var context = new MoviesEntities();
            var js = new JavaScriptSerializer();

            ExportAdultMovies(context, js);

            ExportRatedMoviesByUser(context, js);

            ExportTopFavouriteMovies(context, js);
        }
        private static void ExportRatedMoviesByUser(MoviesEntities context, JavaScriptSerializer js)
        {
            var ratedMoviesByUser = context.Users
                .Select(u => new
                             {
                                 username = u.Username,
                                 ratedMovies = u.Movies.Where(m => m.Ratings.Count > 0) // no idea
                             });

            var output = js.Serialize(ratedMoviesByUser);
            //File.AppendAllText(@"..\..\Results\rated-movies-by-jmeyery.json", output);
            //Console.WriteLine("Export rated-movies-by-jmeyery.json complited!");
        }
Ejemplo n.º 6
0
 static void Main()
 {
     var db = new MoviesEntities();
     var movies = db.Movies.Where(m => m.AgeRestriction == AgeRestriction.Teen).Select(m => new
     {
         m.Isbn,
         m.Title,
         favouriteBy = m.Users.Select(u => u.Username)
     })
     .Take(10);
     foreach (var movie in movies)
     {
         Console.WriteLine(movie.Isbn + " " + movie.Title + " " + string.Join(", ", movie.favouriteBy));
     }
 }
        private static void ExportAdultMovies(MoviesEntities context, JavaScriptSerializer js)
        {
            var allAdultMovies = context.Movies
                .Where(m => m.AgeRestriction == AgeRestriction.Adult)
                .Select(m => new
                             {
                                 title = m.Title,
                                 ratingsGiven = m.Ratings.Count
                             })
                .OrderBy(m => m.title)
                .ThenBy(m => m.ratingsGiven);

            var output = js.Serialize(allAdultMovies);
            File.AppendAllText(@"..\..\Results\adult-movies.json", output);
            Console.WriteLine("Export adult-movies.json complited!");
        }
        private static void ExportTopFavouriteMovies(MoviesEntities context, JavaScriptSerializer js)
        {
            var topTenFavouriteTeenMovies = context.Movies
                .Where(m => m.AgeRestriction == AgeRestriction.Teen)
                .Select(m => new
                             {
                                 isbn = m.Isbn,
                                 title = m.Title,
                                 favouritedBy = m.Ratings.Count // no idea
                             })
                .OrderByDescending(m => m.favouritedBy)
                .ThenBy(m => m.title)
                .Take(10);

            var output = js.Serialize(topTenFavouriteTeenMovies);
            //File.AppendAllText(@"..\..\Results\top-10-favourite-movies.json", output);
            //Console.WriteLine("Export top-10-favourite-movies.json complited!");
        }
Ejemplo n.º 9
0
 private static void ActorsAndMovies()
 {
     Console.WriteLine();
     using (MoviesEntities ctx = new MoviesEntities())
     {
         var actors = from a in ctx.Actors select a;
         foreach (var a in actors)
         {
             Console.WriteLine("{0} {1}", a.FirstName, a.LastName);
             Console.WriteLine(new String('-', 30));
             foreach(var m in a.Filmographies)
             {
                 Console.WriteLine("{0}", m.Movie.Title);
             }
             Console.WriteLine();
         }
     }
 }
Ejemplo n.º 10
0
 public MoviesRepository()
 {
     db = new MoviesEntities();
     MoviesEntities asd = new MoviesEntities();
 }
Ejemplo n.º 11
0
 public PersonRepository()
 {
     db = new MoviesEntities();
 }
Ejemplo n.º 12
0
        private static void MovieSchedules()
        {
            Console.WriteLine();
            using (MoviesEntities ctx = new MoviesEntities())
            {
                var sched = from s in ctx.MovieSchedules join m in ctx.Movies on s.MovieID equals m.MovieID join t in ctx.Theaters on s.TheaterID equals t.TheaterID orderby t.NameOfTheater, s.StartDateAndTime descending select new { TheaterName = t.NameOfTheater, Time = s.StartDateAndTime, Title = m.Title };

                foreach (var s in sched)
                {
                    Console.WriteLine("{0} {1}\n{2}", s.TheaterName, s.Time, s.Title);
                    Console.WriteLine();
                }
            }
        }