Esempio n. 1
0
        private void DeleteSelectedRentalLocally()
        {
            string title = SelectedMovie.Title;

            for (int i = 0; i < MoviesInCart.Count; i++)
            {
                if (MoviesInCart[i].Title.Equals(title))
                {
                    MoviesInCart.Remove(MoviesInCart[i]);
                    break;
                }
            }

            for (int i = 0; i < _rentalsList.Count; i++)
            {
                if (_rentalsList[i].Title.Equals(title))
                {
                    _rentalsList[i].Quantity -= 1;
                    break;
                }
            }

            SelectedMovie = null;

            GetTotalPrice();
        }
Esempio n. 2
0
 private void RefreshShoppingCart(object obj)
 {
     SelectedMovie = null;
     MoviesInCart.Clear();
     GetAllRentals();
     GetMoviesFromCart();
     GetTotalPrice();
 }
Esempio n. 3
0
 private void GetMoviesFromCart()
 {
     MoviesInCart.Clear();
     if (_rentalsList == null)
     {
         _rentalsList = new ObservableCollection <Rental>();
         return;
     }
     if (AllMovies.Count == 0)
     {
         for (int i = 0; i < _rentalsList.Count; i++)
         {
             Movie rental = null;
             try
             {
                 Task t = Task.Run(async() =>
                 {
                     rental = await MovieManagement.MovieManagement.GetMovieAsync(_rentalsList[i].Title);
                 });
                 TimeSpan ts = TimeSpan.FromMilliseconds(10000);
                 if (!t.Wait(ts))
                 {
                     Debug.WriteLine("Timeout.");
                     MessageBox.Show("A timeout occurred");
                 }
                 if (rental != null)
                 {
                     for (int j = 0; j < _rentalsList[i].Quantity; j++)
                     {
                         MoviesInCart.Add(rental);
                     }
                 }
                 else
                 {
                     MessageBox.Show("An error occurred");
                 }
             }
             catch (ArgumentException e)
             {
                 Debug.WriteLine("Argument exception: " + e.Message);
                 MessageBox.Show("An error occurred");
             }
             catch (ServerException)
             {
                 Debug.WriteLine("A server exception occurred");
                 MessageBox.Show("A server exception occurred");
             }
             catch (MovieDoesNotExistException)
             {
                 Debug.WriteLine("Movie does not exist exception");
                 MessageBox.Show("An error occurred");
             }
             catch (Exception e)
             {
                 Debug.WriteLine("An exception occurred: " + e.Message);
                 MessageBox.Show("An error occurred");
             }
         }
     }
     else
     {
         for (int i = 0; i < _rentalsList.Count; i++)
         {
             for (int j = 0; j < AllMovies.Count; j++)
             {
                 if (AllMovies[j].Title.Equals(_rentalsList[i].Title))
                 {
                     for (int k = 0; k < _rentalsList[i].Quantity; k++)
                     {
                         MoviesInCart.Add(AllMovies[j]);
                     }
                     break;
                 }
                 if (j == AllMovies.Count)
                 {
                     // Rental was not found
                     throw new MovieDoesNotExistException();
                 }
             }
         }
     }
 }