Esempio n. 1
0
        public async Task <MoviePageViewModel> GetMoviePage(int page)
        {
            IQueryable <Movie> source = _db.Movies.Include(m => m.Downloader);
            var count = await source.CountAsync();

            if (count == 0)
            {
                return(new MoviePageViewModel(pageNumber: 1, MOVIES_PER_PAGE, totalPages: 1, new List <MovieViewModel>()));
            }

            var totalPages = (int)Math.Ceiling(count / (double)MOVIES_PER_PAGE);

            if (page < 1)
            {
                page = 1;
            }
            else if (page > totalPages)
            {
                page = totalPages;
            }

            var movies = await source
                         .Skip((page - 1) *MOVIES_PER_PAGE)
                         .Take(MOVIES_PER_PAGE)
                         .Select(m => MovieViewModel.FromModel(m, null))
                         .ToListAsync();

            var pageViewModel = new MoviePageViewModel(page, MOVIES_PER_PAGE, totalPages, movies);

            return(pageViewModel);
        }
Esempio n. 2
0
 public ShowDataViewModel(Show obj) : base(obj)
 {
     _moviePVM       = new MoviePageViewModel();
     _theaterPVM     = new TheaterPageViewModel();
     SelectedMovie   = _moviePVM.ItemCollection.FirstOrDefault(e => e.DataObject.Key == obj.MovieKey);
     SelectedTheater = _theaterPVM.ItemCollection.FirstOrDefault(e => e.DataObject.Key == obj.TheaterKey);
 }
Esempio n. 3
0
 /// <summary>
 /// Create an instance of <see cref="PagesViewModel"/>
 /// </summary>
 /// <param name="moviePage">Movie page</param>
 /// <param name="animePage">Anime page</param>
 /// <param name="showPage">Show page</param>
 public PagesViewModel(MoviePageViewModel moviePage, AnimePageViewModel animePage, ShowPageViewModel showPage)
 {
     moviePage.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("MoviesLabel");
     animePage.Caption = LocalizationProviderHelper.GetLocalizedValue <string>("AnimesLabel");
     showPage.Caption  = LocalizationProviderHelper.GetLocalizedValue <string>("ShowsLabel");
     Pages             = new ObservableCollection <IPageViewModel>
     {
         moviePage,
         showPage,
         animePage
     };
 }
Esempio n. 4
0
        public IActionResult MoviePage(int?id)
        {
            var   vm = new MoviePageViewModel();
            var   movieDaoManager = new MovieDaoManager(_context);
            Movie movie           = movieDaoManager.GetMovieById(id.Value);

            if (movie == null)
            {
                return(ControllerRedirect("movies"));
            }

            vm.Movie = movie;
            return(View("~/Views/Movies/Movie.cshtml", vm));
        }
Esempio n. 5
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter is Movie movie)
            {
                ViewModel   = NavigationService.RestoreState <MoviePageViewModel>();
                DataContext = ViewModel;

                if (ViewModel.Movie == null || ViewModel.Movie.TmdbId != movie.TmdbId)
                {
                    ViewModel.Reset();
                    await ViewModel.ReadInfo(movie.TmdbId);
                }

                SetFavButtonToolTip();
            }
        }
Esempio n. 6
0
        public MoviePage()
        {
            InitializeComponent();

            BindingContext = viewModel = new MoviePageViewModel();
        }
        public async Task <IActionResult> Index(int id)
        {
            //se gaseste filmul cerut
            var movie = await _context.Movies.Where(x => x.id == id).FirstOrDefaultAsync();

            //daca nu se gaseste filmul se returneaza mesaj de eroare
            if (movie == null)
            {
                ViewBag.ErrorMessage = "Filmul nu a fost găsit!";
                return(View());
            }

            //lista de date
            //ia ecranizarile care ruleaza in urmatoarea saptamana pt filmul ales
            var screeningsdates = await _context.Screenings.Where(x => x.movieId == id).Where(x => x.date > DateTime.Now.AddDays(-1)).Where(x => x.date <= DateTime.Now.AddDays(6)).OrderBy(X => X.date).ToListAsync();


            //lista de date calendaristice in care ruleaza filmul
            List <DateTime> dates = new List <DateTime>();

            foreach (var screening in screeningsdates)
            {
                if (!dates.Contains(screening.date))
                {
                    dates.Add(screening.date);
                }
            }


            //apelare API
            var client = new HttpClient();

            //se obtin genurile
            var titlu = movie.title;


            //se obtine id-ul filmului din baza de date interogata
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri("https://imdb8.p.rapidapi.com/title/find?q=" + titlu),
                Headers    =
                {
                    { "x-rapidapi-key",  Configuration.GetValue <string>("ApiKey") },
                    { "x-rapidapi-host", "imdb8.p.rapidapi.com"                    },
                },
            };
            //get api response
            var response = await client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            //get body of response as string
            var body = await response.Content.ReadAsStringAsync();

            //get list of ids returned
            FindResult movies = new FindResult();
            string     IMDBid = "";
            int        i      = 0;

            movies = JsonConvert.DeserializeObject <FindResult>(body);
            //se gaseste primul rezultat tip titlu
            foreach (var movieresulted in movies.results)
            {
                if (movieresulted.id.Substring(1, movieresulted.id.Length - 12) == "title")
                {
                    IMDBid = movieresulted.id;
                    break;
                }
                else
                {
                    i++;
                }
            }

            List <string> genres = new List <string>();
            List <string> actors = new List <string>();
            double        rating = 0;


            //se verifica daca s-a gasit vreun film
            if (IMDBid != "")
            {
                //remove /title and last slash
                IMDBid = IMDBid.Substring(7, IMDBid.Length - 8);

                //get de movie genre
                var request2 = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri("https://imdb8.p.rapidapi.com/title/get-genres?tconst=" + IMDBid),
                    Headers    =
                    {
                        { "x-rapidapi-key",  Configuration.GetValue <string>("ApiKey") },
                        { "x-rapidapi-host", "imdb8.p.rapidapi.com"                    },
                    },
                };

                //get response
                var response2 = await client.SendAsync(request2);

                if (response2.StatusCode != HttpStatusCode.OK)
                {
                    genres.Add("N/A");
                }
                else
                {               //get list of genres
                    var body2 = await response2.Content.ReadAsStringAsync();

                    genres = JsonConvert.DeserializeObject <List <string> >(body2);
                }



                //get IMDB rating
                var request3 = new HttpRequestMessage
                {
                    Method     = HttpMethod.Get,
                    RequestUri = new Uri("https://imdb8.p.rapidapi.com/title/get-ratings?tconst=" + IMDBid),
                    Headers    =
                    {
                        { "x-rapidapi-key",  Configuration.GetValue <string>("ApiKey") },
                        { "x-rapidapi-host", "imdb8.p.rapidapi.com"                    },
                    },
                };
                var response3 = await client.SendAsync(request3);

                if (response3.StatusCode == HttpStatusCode.OK)
                {
                    IMDBRating ratingresult = new IMDBRating();
                    var        body3        = await response3.Content.ReadAsStringAsync();

                    ratingresult = JsonConvert.DeserializeObject <IMDBRating>(body3);
                    rating       = ratingresult.rating;
                }

                //get leading actors
                var actorsresult = movies.results[i].principals;
                if (actorsresult != null)
                {
                    foreach (var a in actorsresult)
                    {
                        actors.Add(a.name);
                    }
                }
                else
                {
                    actors.Add("N/A");
                }
            }
            else
            {
                genres.Add("N/A");
                actors.Add("N/A");
            }


            //se creaza modelul final care se trimite pe front-end
            MoviePageViewModel model = new MoviePageViewModel();

            model.id           = movie.id;
            model.title        = movie.title;
            model.video        = movie.video;
            model.img          = movie.img;
            model.description  = movie.description;
            model.duration     = movie.duration;
            model.release_date = movie.release_date;
            model.genres       = genres;
            model.actors       = actors;
            model.rating       = rating;
            model.dates        = dates;

            return(View(model));
        }
 public BuyTicketFlowViewModelStart()
     : base(AppViewModelBase.AppFrameInstance, typeof(BuyTicketViewA))
 {
     _moviePVM = new MoviePageViewModel();
 }