Exemplo n.º 1
0
        /// <summary>
        /// Gets all movies.
        /// </summary>
        /// <param name="filter">Movie filter.</param>
        /// <returns>Gets collection of all movies.</returns>
        public async Task<IEnumerable<Movie>> GetAllMoviesAsync(MoviesFilter filter)
        {
            try
            {
               return await MovieContext.Movies
                    .Where(item => String.IsNullOrEmpty(filter.SearchMovie) ? item != null : item.Title.Contains(filter.SearchMovie))
                    .Where(item => Guid.Empty == filter.MovieStatusId ? item != null : item.StatusId == filter.MovieStatusId)
                    .Where(item => Guid.Empty == filter.MovieCategoryId ? item != null : item.CategoryId == filter.MovieCategoryId)
                    .OrderBy(filter.Ordering)
                    .ToPagedListAsync(filter.PageNumber, filter.PageSize);
            }

            catch (Exception e)
            {                
                throw e;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Index action.
        /// </summary>
        /// <param name="movieCategoryId">Movie category id.</param>
        /// <param name="movieStatusId">Movie status id.</param>
        /// <param name="searchMovie">Search movie.</param>
        /// <param name="pageNumber">Page number.</param>
        /// <param name="pageSize">Page size.</param>
        /// <param name="ordering">Ordering.</param>
        /// <returns>Index page.</returns>
        public async Task<ActionResult> Index(Guid? movieCategoryId, Guid? movieStatusId, string searchMovie, int pageNumber = 1, int pageSize = 12, string ordering = "Title")
        {
            MoviesFilter filter = new MoviesFilter(pageNumber, pageSize, ordering, searchMovie, movieStatusId, movieCategoryId);

            ViewBag.Statuses = new SelectList(await movieService.GetMovieStatuses(), "Id", "Name");
            ViewBag.Categories = new SelectList(await movieService.GetMovieCategories(), "Id", "Name");

            IEnumerable<Movie> movies = await movieService.GetAllMoviesAsync(filter);
            await movieService.MoviesChangedStatus(movies);

            ViewBag.SortTitle = ordering == "Title" ? "Title desc" : "Title";
            ViewBag.SortCategory = ordering == "Category.Name" ? "Category.Name desc" : "Category.Name";
            ViewBag.SortRating = ordering == "Rating" ? "Rating desc" : "Rating";
            ViewBag.SortYear = ordering == "Year" ? "Year desc" : "Year";
            ViewBag.CurrentSort = ordering;
            ViewBag.CurrentSearch = searchMovie;
            ViewBag.CurrentStatus = movieStatusId;
            ViewBag.CurrentCategory = movieCategoryId;

            return View(movies);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets all movies.
 /// </summary>
 /// <returns>Movies.</returns>
 public async Task<IEnumerable<Movie>> GetAllMoviesAsync(MoviesFilter filter)
 {
     return await movieRepository.GetAllMoviesAsync(filter); 
 }