private void RefreshShoppingCart(object obj) { SelectedMovie = null; MoviesInCart.Clear(); GetAllRentals(); GetMoviesFromCart(); GetTotalPrice(); }
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(); } } } } }