public MovieListViewModel(IService service) { Service = service; MovieFilter = new MovieFilter(); SelectedMovie = null; NewMovie = null; NewActor = null; NewDirector = null; MovieFilterCommand = new FilterCommand(this); NewMovieCommand = new NewItemCommand(this); CancelNewMovieCommand = new CancelNewItemCommand(this); SaveMovieCommand = new SaveMovieCommand(this); DownloadPosterFromWebApiCommand = new DownloadPosterFromWebApiCommand(this); AddGenreCommand = new AddGenreCommand(this); AddCountryCommand = new AddCountryCommand(this); AddDirectorCommand = new AddDirectorCommand(this); AddActorCommand = new AddActorCommand(this); NewDirectorCommand = new NewDirectorCommand(this); NewActorCommand = new NewActorCommand(this); CancelNewActorCommand = new CancelNewActorCommand(this); CancelNewDirectorCommand = new CancelNewDirectorCommand(this); SaveActorCommand = new SaveActorCommand(this); SaveDirectorCommand = new SaveDirectorCommand(this); RemoveMovieCommand = new RemoveMovieCommand(this); Genres = new ObservableCollection <Genre>(); Countries = new ObservableCollection <Country>(); Directors = new ObservableCollection <Director>(); Actors = new ObservableCollection <Actor>(); }
private void btnOk_Click(object sender, EventArgs e) { MovieFilter filter = TVSettings.Instance.MovieFilter; filter.ShowName = string.IsNullOrEmpty(tbShowName.Text) ? null : tbShowName.Text; filter.ShowStatus = string.IsNullOrEmpty(cmbShowStatus.Text) ? null : cmbShowStatus.SelectedItem.ToString(); filter.ShowNetwork = string.IsNullOrEmpty(cmbNetwork.Text) ? null : cmbNetwork.SelectedItem.ToString(); filter.ShowRating = string.IsNullOrEmpty(cmbRating.Text) ? null : cmbRating.SelectedItem.ToString(); filter.ShowYear = string.IsNullOrEmpty(cmbYear.Text) ? null : cmbYear.SelectedItem.ToString(); filter.ShowStatusInclude = GetIncludeStatus(cmbShowStatusType); filter.ShowNetworkInclude = GetIncludeStatus(cmbNetworkType); filter.ShowRatingInclude = GetIncludeStatus(cmbRatingType); filter.ShowYearInclude = GetIncludeStatus(cmbYearType); filter.Genres.Clear(); foreach (string genre in clbGenre.CheckedItems) { filter.Genres.Add(genre); } doc.SetDirty(); DialogResult = DialogResult.OK; Close(); }
/// <summary> /// get movies by filter /// </summary> /// <param name="filter">filter</param> /// <returns></returns> private MovieList QueryMovies(MovieFilter filter) { IEnumerable <Movie> movies = repository.Movies; if (!String.IsNullOrEmpty(filter.Keywords)) { movies = movies.Where(m => m.Title.ContainsIgnoreCase(filter.Keywords) || (m.HasDetail && m.Actors.ContainsIgnoreCase(filter.Keywords))); } movies = FilterByGenre(movies, filter.Genre); movies = FilterByCountry(movies, filter.Country); movies = FilterByYear(movies, filter.Year); movies = FilterByPrice(movies, filter.Price); MovieList model = new MovieList { Movies = movies .OrderBy(m => m.Price) .Skip((filter.Page - 1) * ITEM_PER_PAGE) .Take(ITEM_PER_PAGE), Pages = new Models.PageInfo { CurrentPage = filter.Page, ItemPerPage = ITEM_PER_PAGE, TotalItems = movies.Count() } }; return(model); }
public List <MovieListItemModel> SearchMovie(string movieName) { var filter = new MovieFilter { MovieName = movieName }; var result = this._movieRepository.GetFilteredMovies(filter); if (result != null) { return(result.Select(x => new MovieListItemModel { Id = x.Id, Name = x.Name, ThumbnailUrl = x.ThumbnailUrl, ShowTimes = x.ShowTimes?.Select(t => new ShowTimeModel { CinemaName = t.Cinema?.Name, Time = t.Time }) .ToList() }).ToList()); } return(null); }
/// <summary> /// Callback that is invoked when the filter is reset. /// </summary> /// /// <param name="_">The filter.</param> private async Task OnFilterResetAsync(MovieFilter _) { // Reset the filter this.Filter = BuildDefaultFilter(); // Update the movies await this.GetMoviesAsync(); }
public IEnumerable <Movie> GetFilteredMovies(MovieFilter filter) { var query = this._database.Movies.AsQueryable(); query = ApplyFilter(query, filter); return(query.Include(p => p.ShowTimes).ThenInclude(p => p.Cinema).ToList()); }
private static IQueryable <Movie> ApplyFilter(IQueryable <Movie> query, MovieFilter filter) { if (!string.IsNullOrWhiteSpace(filter.MovieName)) { query = query.Where(x => x.Name.Contains(filter.MovieName)); } return(query); }
public void MovieFilterTestIfSomeParamsAreNull() { const string movieName = "Movie name"; var filter = new MovieFilter(Guid.NewGuid(), movieName, null, null); Assert.IsTrue(filter.Name == movieName); Assert.IsNull(filter.Rating); Assert.IsNull(filter.Year); }
/// <summary> /// Callback that is invoked when the filter is applied. /// </summary> /// /// <param name="_">The filter.</param> private async Task OnFilterSearchAsync(MovieFilter _) { // Reset the paging this.Filter.PageNumber = 1; this.Filter.PageSize = this.Filter.PageSize; // Update the movies await this.GetMoviesAsync(); }
public void MovieFilterTestIfAllParamsAreNull() { var filter = new MovieFilter(null, null, null, null); Assert.IsNull(filter.Rating); Assert.IsNull(filter.Name); Assert.IsNull(filter.Year); Assert.IsNull(filter.Id); }
internal static bool IsValidMovieFilter(MovieFilter filter) { //If no filter values are set, then the filter is considered invalid if (String.IsNullOrEmpty(filter.Title) && filter.YearOfRelease == 0 && (filter.Genres == null || filter.Genres.Length == 0)) { return(false); } return(true); }
/// <summary> /// Get movies, according to special filter /// Main use is loading data, when page is first loaded /// </summary> /// <param name="filter">filter</param> /// <returns>json</returns> public JsonResult Movies(MovieFilter filter) { JsonResult json = new JsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.ContentEncoding = Encoding.UTF8; json.ContentType = "application/json"; json.Data = QueryMovies(filter); return(json); }
public void MovieFilterTestIfAllParamsAreCorrect() { const string name = "My Movie"; const int rating = 10; const int year = 2009; var filter = new MovieFilter(Guid.NewGuid(), name, rating, year); Assert.IsTrue(filter.Rating == rating); Assert.IsTrue(filter.Name == name); Assert.IsTrue(filter.Year == year); }
public void GetMovie_with_no_filter_return_badrequest() { MoviesApiContext context = MoviesApiContext.CreateContextWithDataForTesting(); MoviesController controller = new MoviesController(context); MovieFilter filter = new MovieFilter(); var result = controller.GetMovie(filter); Assert.IsType <BadRequestResult>(result); }
public void CanFilterMoviesByProducer() { var filter = new MovieFilter { Producer = "Steven Spielberg", }; var result = _controller.GetMovie(filter); var movies = result.Should().BeAssignableTo <IEnumerable <Movie> >().Subject; movies.Should().OnlyContain(movie => movie.Producer == filter.Producer); }
public void CanFilterMoviesByGenre() { var filter = new MovieFilter { Genre = "Comedy" }; var result = _controller.GetMovie(filter); var movies = result.Should().BeAssignableTo <IEnumerable <Movie> >().Subject; movies.Should().OnlyContain(movie => movie.Genre == filter.Genre); }
public void CanFilterMoviesByYear() { var filter = new MovieFilter { Year = 2002 }; var result = _controller.GetMovie(filter); var movies = result.Should().BeAssignableTo <IEnumerable <Movie> >().Subject; movies.Should().OnlyContain(movie => movie.Year == filter.Year); }
public void CanPaginateResults() { var filter = new MovieFilter { Page = 2, Size = 2 }; var result = _controller.GetMovie(filter); var movies = result.Should().BeAssignableTo <IEnumerable <Movie> >().Subject; movies.First().Id.Should().Be(3); }
/// <summary> /// Builds the default filter from the built-in constants. /// </summary> private static MovieFilter BuildDefaultFilter() { // Create the filter var filter = new MovieFilter { PageNumber = INITIAL_PAGE_NUMBER, PageSize = INITIAL_PAGE_SIZE, OrderBy = MovieFilterOrderBy.Name, OrderDirection = MovieFilterOrderDirection.Ascending }; return(filter); }
public List <MovieResult> SearchMoviesByFilter(MovieFilter filter) { if (string.IsNullOrEmpty(filter.Title) && filter.ReleaseYear.HasValue == false && filter.Genres.Any() == false) { throw new InvalidInputException(); } var moviesQuery = moviesRepository.GetMovies(); if (string.IsNullOrEmpty(filter.Title) == false) { moviesQuery = moviesQuery.Where(m => m.Title.StartsWith(filter.Title)); } if (filter.ReleaseYear.HasValue) { moviesQuery = moviesQuery.Where(m => m.ReleaseYear == filter.ReleaseYear); } if (filter.Genres.Any()) { var aggregatedValue = filter.Genres.Aggregate((aggr, next) => next | aggr); moviesQuery = moviesQuery.Where(m => (m.Genre & aggregatedValue) == aggregatedValue); } var movies = moviesQuery.Select(m => new MovieResult() { Id = m.Id, Title = m.Title, ReleaseYear = m.ReleaseYear, RunningTime = m.RunningTime, AverageRating = (int)m.Genre }).ToList(); var moviesIds = movies.Select(m => m.Id).ToArray(); var moviesRatings = moviesRepository.GetUserRatings().Where(ur => moviesIds.Contains(ur.MovieId)).GroupBy(ur => ur.MovieId) .Select(g => new { MovieId = g.Key, AverageRating = g.Average(x => x.Rating) }).ToList(); foreach (var movie in movies) { movie.AverageRating = RoundingUtils.RoundToNearestDot5(moviesRatings.SingleOrDefault(r => r.MovieId == movie.Id)?.AverageRating); } return(movies); }
public void GetMovie_with_filter_noresults_return_notfound() { MoviesApiContext context = MoviesApiContext.CreateContextWithDataForTesting(); MoviesController controller = new MoviesController(context); MovieFilter filter = new MovieFilter { Title = "bad title" }; var result = controller.GetMovie(filter); Assert.IsType <NotFoundResult>(result); }
/// <inheritdoc /> public async Task <MementoResponse <Page <MovieListContract> > > GetAllAsync(MovieFilter movieFilter = null) { var parameters = new Dictionary <string, string>(); // Build the parameters if (movieFilter != null) { // Populate the filter parameters if (string.IsNullOrWhiteSpace(movieFilter.Name) == false) { parameters.Add(nameof(movieFilter.Name), movieFilter.Name); } if (string.IsNullOrWhiteSpace(movieFilter.Summary) == false) { parameters.Add(nameof(movieFilter.Summary), movieFilter.Summary); } if (movieFilter.ReleasedAfter != null) { parameters.Add(nameof(movieFilter.ReleasedAfter), movieFilter.ReleasedAfter.Value.ToUtcString()); } if (movieFilter.ReleasedBefore != null) { parameters.Add(nameof(movieFilter.ReleasedBefore), movieFilter.ReleasedBefore.Value.ToUtcString()); } if (movieFilter.InTheaters != null) { parameters.Add(nameof(movieFilter.InTheaters), movieFilter.InTheaters.ToString()); } // Populate the pagination parameters parameters.Add(nameof(movieFilter.PageNumber), movieFilter.PageNumber.ToString()); parameters.Add(nameof(movieFilter.PageSize), movieFilter.PageSize.ToString()); parameters.Add(nameof(movieFilter.OrderBy), movieFilter.OrderBy.ToString()); parameters.Add(nameof(movieFilter.OrderDirection), movieFilter.OrderDirection.ToString()); } // Invoke the API var response = await this.HttpService.GetAsync <Page <MovieListContract> >($"{API_URL}", parameters); if (!response.Success) { throw new ApplicationException(string.Join(Environment.NewLine, response.Errors)); } else { return(response); } }
public ActionResult <IEnumerable <MovieResult> > Get([FromQuery] MovieFilter filter) { try { var movies = searchService.SearchMoviesByFilter(filter); if (movies.Any() == false) { return(NotFound("Movies not found")); } return(movies); } catch (Movies.Services.InvalidInputException) { return(BadRequest()); } }
public async Task <ActionResult <MovieViewModel> > API_A([FromQuery] MovieFilter filter) { if (!MovieHelper.IsValidMovieFilter(filter)) { return(BadRequest()); } List <Movie> movies = await _movieCollectionService.GetMoviesByFilter(filter); if (movies.Count > 0) { return(Ok(MovieHelper.GetMovieViewModels(movies))); } return(NotFound()); }
private void SetButtonStates() { MovieFilter filter = TVSettings.Instance.MovieFilter; { //Filter By Show Names bool filterByShowNames = filter.ShowName != null; tbShowName.Text = filterByShowNames ? filter.ShowName : string.Empty; //Filter By Show Status bool filterByShowStatus = filter.ShowStatus != null; cmbShowStatus.SelectedItem = filterByShowStatus ? filter.ShowStatus : string.Empty; //Filter By Show Rating bool filterByShowRating = filter.ShowRating != null; cmbRating.SelectedItem = filterByShowRating ? filter.ShowRating : string.Empty; //Filter By Show Network bool filterByShowNetwork = filter.ShowNetwork != null; cmbNetwork.SelectedItem = filterByShowNetwork ? filter.ShowNetwork : string.Empty; //Filter By Show Network bool filterByShowYear = filter.ShowYear != null; cmbYear.SelectedItem = filterByShowYear ? filter.ShowYear : string.Empty; //Filter By Show Status cmbShowStatusType.SelectedItem = filter.ShowStatusInclude ? IS : IS_NOT; //Filter By Show Rating cmbRatingType.SelectedItem = filter.ShowRatingInclude ? IS : IS_NOT; //Filter By Show Network cmbNetworkType.SelectedItem = filter.ShowNetworkInclude ? IS : IS_NOT; //Filter By Show Network cmbYearType.SelectedItem = filter.ShowYearInclude ? IS : IS_NOT; //Filter By Genre foreach (string genre in filter.Genres) { int genreIndex = clbGenre.Items.IndexOf(genre); if (genreIndex > 0) { clbGenre.SetItemChecked(genreIndex, true); } } } }
public void GetMovie_with_genre_filter_return_multiple() { MoviesApiContext context = MoviesApiContext.CreateContextWithDataForTesting(); MoviesController controller = new MoviesController(context); MovieFilter filter = new MovieFilter { Genre = "Drama" }; var result = controller.GetMovie(filter); var objectResult = result as ObjectResult; var value = objectResult.Value as List <MovieItem>; Assert.Equal(3, value.Count); }
public JsonResult Paginate(MovieFilter filter, int page) { if (page <= 0) { page = 1; } filter.Page = page; JsonResult json = new JsonResult(); json.ContentEncoding = Encoding.UTF8; json.ContentType = "application/json"; json.Data = QueryMovies(filter); return(json); }
public void GetMovie_with_part_filter_values_dont_repeat() { MoviesApiContext context = MoviesApiContext.CreateContextWithDataForTesting(); MoviesController controller = new MoviesController(context); MovieFilter filter = new MovieFilter { Title = "Shawshank", Year = 1994 }; var result = controller.GetMovie(filter); var objectResult = result as ObjectResult; var value = objectResult.Value as List <MovieItem>; Assert.Single(value); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { MovieFilter filter = null; if (controllerContext.HttpContext.Session != null) { filter = controllerContext.HttpContext.Session[SessionKey] as MovieFilter; } if (filter == null) { filter = new MovieFilter(); if (controllerContext.HttpContext.Session != null) { controllerContext.HttpContext.Session[SessionKey] = filter; } } return(filter); }
public async Task <ActionResult <MementoResponse <IPage <MovieListContract> > > > GetUpcomingReleasesAsync() { // Build the 'UpcomingReleases' filter var filter = new MovieFilter { InTheaters = MovieFilterInTheaters.Unchecked, ReleasedAfter = DateTime.Today, PageNumber = 1, PageSize = 3, OrderBy = MovieFilterOrderBy.ReleaseDate, OrderDirection = MovieFilterOrderDirection.Ascending }; // Get the movies var movies = await this.Repository.GetAllAsync(filter); // Build the response return(this.BuildGetAllResponse <Movie, MovieListContract>(movies)); }