Example #1
0
        public async Task <MovieResponse> UpdateAsync(int id, Movie movie, MoviesQuery query, string imdbID)
        {
            var existingMovieList = await _movieListRepository.FindByIdAsync(id);

            var existingMovie = await _movieRepository.FindByIdAsync(id, imdbID);

            if (existingMovie == null || existingMovieList == null || !(existingMovieList.ApplicationUserRefId.Equals(query.ApplicationUserRefId)))
            {
                return(new MovieResponse("Movie not found."));
            }

            existingMovie.Watched = movie.Watched;

            try
            {
                _movieRepository.Update(existingMovie);
                await _unitOfWork.CompleteAsync();

                return(new MovieResponse(existingMovie));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new MovieResponse($"An error occurred when updating the movie: {ex.Message}"));
            }
        }
Example #2
0
        // GET api/<controller>
        // If a collection of ratings needs to be sent [FromUri] is required.
        public IEnumerable <SelectListItem> ByManyStarRating([FromUri] int[] selectedStarRating)
        {
            var queryable = new MoviesQuery(db);
            var genres    = queryable.WhereMovieRatingGreater(selectedStarRating).Select(m => new SelectListItem()
            {
                Text = m.Genre, Value = m.Genre
            });

            return(genres);
        }
Example #3
0
        // GET api/<controller>
        public IEnumerable <SelectListItem> Get()
        {
            var queryable = new MoviesQuery(db);
            var genres    = queryable.WhereMovieRatingGreater(1).Select(m => new SelectListItem()
            {
                Text = m.Genre, Value = m.Genre
            });

            return(genres);
        }
Example #4
0
        public async Task <IActionResult> Index(string searchString, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation("Getting item list");
            var request = new MoviesQuery {
                QueryString = searchString
            };

            var movies = await _mediator.Send(request, cancellationToken);

            //TODO add paging with skip and limit

            return(View(movies));
        }
Example #5
0
        public async Task <IList <MovieViewModel> > Handle(MoviesQuery moviesQuery, CancellationToken cancellationToken = default)
        {
            Check.NotNull(moviesQuery, nameof(moviesQuery));
            IList <DbMovie> movies;

            // TODO filter!!!
            if (string.IsNullOrEmpty(moviesQuery.QueryString))
            {
                movies = await _movieDbService.GetAsync(cancellationToken).ConfigureAwait(false);
            }
            else
            {
                movies = await _movieDbService.GetAsync(moviesQuery.QueryString, nameof(DbMovie.Title), cancellationToken).ConfigureAwait(false);
            }

            return(_mapper.Map <List <MovieViewModel> >(movies));
        }
Example #6
0
        public async Task <MovieResponse> SaveAsync(Movie movie, MoviesQuery query)
        {
            var existingMovieList = await _movieListRepository.FindByIdAsync(movie.MovieListRefId);

            if (existingMovieList == null || !(existingMovieList.ApplicationUserRefId.Equals(query.ApplicationUserRefId)))
            {
                return(new MovieResponse("Could not save movie."));
            }

            try
            {
                await _movieRepository.AddAsync(movie);

                await _unitOfWork.CompleteAsync();

                return(new MovieResponse(movie));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new MovieResponse($"An error occurred when saving the movie: {ex.Message}"));
            }
        }