Exemplo n.º 1
0
 public async Task SearchMovieAsync(int theMovieDbId)
 {
     try
     {
         var movie = await _searcher.SearchMovieAsync(new MovieRequest(_user, _categoryId), theMovieDbId);
         await HandleMovieSelectionAsync(movie);
     }
     catch
     {
         await _userInterface.WarnNoMovieFoundByTheMovieDbIdAsync(theMovieDbId.ToString());
     }
 }
        public async Task HandleMovieRequestAsync(string movieName)
        {
            var movies = await _searcher.SearchMovieAsync(movieName);

            if (!movies.Any())
            {
                await _userInterface.WarnNoMovieFoundAsync(movieName);
            }
            else if (movies.Count > 1)
            {
                var movieSelection = await _userInterface.GetMovieSelectionAsync(movies);

                if (!movieSelection.IsCancelled && movieSelection.Movie != null)
                {
                    var movie = movieSelection.Movie;
                    await HandleMovieSelectionAsync(movie);
                }
                else if (!movieSelection.IsCancelled)
                {
                    await _userInterface.WarnInvalidMovieSelectionAsync();
                }
            }
            else if (movies.Count == 1)
            {
                var movie = movies.Single();
                await HandleMovieSelectionAsync(movie);
            }
        }
Exemplo n.º 3
0
        public async Task AddNotificationAsync(string userId, int theMovieDbId)
        {
            var movie = await _movieSearcher.SearchMovieAsync(new MovieRequest(null, int.MinValue), theMovieDbId);

            _notificationsRepository.AddNotification(userId, int.Parse(movie.TheMovieDbId));
            await _userInterface.DisplayNotificationSuccessAsync(movie);
        }
Exemplo n.º 4
0
        public async Task <IReadOnlyList <Movie> > SearchMoviesAsync(string movieName)
        {
            IReadOnlyList <Movie> movies = Array.Empty <Movie>();

            if (movieName.Trim().ToLower().StartsWith("tmdb"))
            {
                var theMovieDbIdTextValue = movieName.ToLower().Split("tmdb")[1]?.Trim();

                if (int.TryParse(theMovieDbIdTextValue, out var theMovieDbId))
                {
                    try
                    {
                        var movie = await _searcher.SearchMovieAsync(theMovieDbId);

                        movies = new List <Movie> {
                            movie
                        }.Where(x => x != null).ToArray();
                    }
                    catch
                    {
                        movies = new List <Movie>();
                    }

                    if (!movies.Any())
                    {
                        await _userInterface.WarnNoMovieFoundByTheMovieDbIdAsync(theMovieDbIdTextValue);
                    }
                }
                else
                {
                    await _userInterface.WarnNoMovieFoundByTheMovieDbIdAsync(theMovieDbIdTextValue);
                }
            }
            else
            {
                movieName = movieName.Replace(".", " ");
                movies    = await _searcher.SearchMovieAsync(movieName);

                if (!movies.Any())
                {
                    await _userInterface.WarnNoMovieFoundAsync(movieName);
                }
            }

            return(movies);
        }