Exemple #1
0
 /// <summary>
 /// Called when the user presses the "Rent movie" button, it first checks whether it's possible to rent a movie,
 /// <para>and if it is, proceeds to update the list of rented movies of the logged user</para>
 /// </summary>
 private void rentMovie()
 {
     if (lbMovies.SelectedItem != null && LoggedUser != null)
     {
         CustomMovie selectedMovie = lbMovies.SelectedItem as CustomMovie;
         if (LoggedUser.Movies.ContainsKey(selectedMovie.Movie.Title))
         {
             MessageBox.Show(string.Format("{0} is already rented!", selectedMovie.Movie.Title), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         else if (LoggedUser.Movies.Count() >= 5)
         {
             MessageBox.Show("Maximum number of rented movies (5) reached!\nReturn a rented movie or wait for a rental to expire", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             RentTime rentTime = new RentTime();
             if (rentTime.ShowDialog() == DialogResult.OK)
             {
                 LoggedUser.Movies.Add(selectedMovie.Movie.Title, DateTime.Now.AddDays(+rentTime.Days).ToString("dd/MM/yyyy HH:mm:ss"));
                 MessageBox.Show(string.Format("{0} was successfully rented", selectedMovie.Movie.Title));
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Set genreal info for the selected movie and call methods to load additional info
        /// </summary>
        private async void setMovieInfo()
        {
            CustomMovie cm = lbMovies.SelectedItem as CustomMovie;

            if (!cm.Movie.Title.Equals(currentMovie.Title))
            {
                pbPoster.SizeMode = PictureBoxSizeMode.CenterImage;
                pbPoster.Image    = Properties.Resources.loading;
                Movie movie = await LoadMovies.GetMovie(cm);

                if (movie.ReleaseDate.HasValue)
                {
                    lblMovieTitle.Text = string.Format("{0} ({1})", movie.Title, movie.ReleaseDate.Value.Year.ToString());
                }
                else
                {
                    lblMovieTitle.Text = movie.Title;
                }
                lblRating.Text         = movie.VoteAverage.ToString("0.00");
                lblVotes.Text          = movie.VoteCount.ToString();
                pbPoster.SizeMode      = PictureBoxSizeMode.Zoom;
                pbPoster.ImageLocation = "http://image.tmdb.org/t/p/w500" + movie.Poster;
                lblDescription.Text    = movie.Overview;
                setCast(movie.Credits.Cast);
                setInfo(movie);
                setTrailer(movie.Videos.Results);
                currentMovie = movie;
            }
        }
Exemple #3
0
        /// <summary>
        /// Get a Movie object that contains more info about the requested movie through a CustomMovie object
        /// </summary>
        /// <param name="cm"></param>
        /// <returns></returns>
        public static async Task <Movie> GetMovie(CustomMovie cm)
        {
            using (var client = new ServiceClient(Key))
            {
                try
                {
                    Movie movie = await client.Movies.GetAsync(cm.Movie.Id, null, true, token);

                    return(movie);
                }
                catch (ServiceRequestException)
                {
                    MessageBox.Show("Too many requests, please wait for a few moments");
                    return(null);
                }
            }
        }