// GET: api/Movies public List <MoviesViewModel> Getmovies() { var listOfMovies = db.visnings.OrderBy(v => v.date); // Get movies and sort them in date order var resultList = new List <MoviesViewModel>(); // Define the return structure foreach (var movie in listOfMovies) // For each movie in the viewings table (plus lounge information) { try { var movieFromMovieDB = MovieFetcher.GetMovie(movie.movieid); // Make a fetch to Movie DB to get information about a movie // To the return list, add a View Model and add the information from both the Viewing, Lounge and MovieDB into a single object resultList.Add(new MoviesViewModel { Id = movie.id, MovieName = movieFromMovieDB.Title, // Title for the Movie from the MovieDB Length = movieFromMovieDB.Runtime ?? 0, // The runtime from MovieDB Adult = movieFromMovieDB.Adult, // If it's a adult movie, from MovieDB LoungeName = movie.salong, // The lounge name from Lounge entity in the database (contected using Entity Framework) ViewingDate = movie.date, // Date of the viewing from the Viewing entity in the database TotalSeats = movie.maxseats, // And number of seats in the Lounge Picture = movieFromMovieDB.PosterPath }); } catch { return(new List <MoviesViewModel>()); } } return(resultList); // Return the list of Movies }
// API URL POST http://localhost:52662//api/viewings // XXXXX - Port number // Desc: Returns a list of Viewing View Models, a.k.a a list of shows that will be displayed as a list of movies to be shown public List <ViewingViewModel> GetViewings() { var listOfViewings = db.viewing.Include(v => v.lounge).OrderBy(v => v.date); // Get viewings plus the laoung and sort them in date order var listOfMovies = new List <ViewingViewModel>(); // Define the return structure foreach (var viewing in listOfViewings) // For each movie in the viewings table (plus lounge information) { var movie = MovieFetcher.GetMovie(viewing.moviedbid); // Make a fetch to Movie DB to get information about a movie // To the return list, add a View Model and add the information from both the Viewing, Lounge and MovieDB into a single object listOfMovies.Add(new ViewingViewModel { MovieName = movie.Title, // Title for the Movie from the MovieDB Length = movie.Runtime ?? 0, // The runtime from MovieDB Adult = movie.Adult, // If it's a adult movie, from MovieDB LoungeName = viewing.lounge.name, // The lounge name from Lounge entity in the database (contected using Entity Framework) ViewingDate = viewing.date, // Date of the viewing from the Viewing entity in the database TotalSeats = viewing.lounge.seat.Count(), // And number of seats in the Lounge PosterPath = movie.PosterPath, Overview = movie.Overview, Bookable = viewing.bookable }); } return(listOfMovies); // Return the list of Movies }
// GET: api/Viewings public List <ViewvingsViewModel> Getmovies() { var listOfMovies = db.Viewings.Include("Salon").Include("MovieApi").OrderBy(v => v.ViewingDate); var resultList = new List <ViewvingsViewModel>(); foreach (var item in listOfMovies) { var movieFromMovieDB = MovieFetcher.GetMovie(item.MovieApi.MovieKey); resultList.Add(new ViewvingsViewModel { Id = item.ViewingID, MovieName = movieFromMovieDB.Title, Length = movieFromMovieDB.Runtime ?? 0, Adult = movieFromMovieDB.Adult, LoungeName = item.Salon.SalonNumber.ToString(), ViewingDate = item.ViewingDate, TotalSeats = GetSeats(item.ViewingID, item.Salon.MaxSeats), Poster = movieFromMovieDB.PosterPath }); } return(resultList); }