Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            IEnumerable <UserRate> userRates = await User.GetUserRatesAsync(userRateRep);

            var baseRequest = movieRep.Movies
                              //.Where(m => !userRates.Select(ur => ur.TitleId).Contains(m.Id))
                              .Where(m => m.ReleaseDate.HasValue && m.ReleaseDate.Value.Year > (DateTime.Now.Year - 2))
                              .Where(m => m.VoteCount > 100);

            if (userRates != null)
            {
                baseRequest = baseRequest.Where(m => !userRates.Select(ur => ur.TitleId).Contains(m.Id));
            }

            var moviesOnCinema = await baseRequest
                                 .OrderByDescending(m => m.ReleaseDate)
                                 .Take(5)
                                 .ToListAsync();

            var recommendedMovies = await baseRequest
                                    .OrderByDescending(m => m.VoteAverage)
                                    .Take(10)
                                    .ToListAsync();

            recommendedMovies.ForEach(m => m.VoteAverage = 8);
            recommendedMovies[0].VoteAverage             = recommendedMovies[1].VoteAverage = recommendedMovies[2].VoteAverage = 10;
            recommendedMovies[3].VoteAverage             = recommendedMovies[4].VoteAverage = recommendedMovies[5].VoteAverage = 9.6;

            var interestingMovies = await baseRequest
                                    .Where(m => !recommendedMovies.Select(mv => mv.Id).Contains(m.Id))
                                    .Where(m => m.VoteAverage >= 7)
                                    .OrderByDescending(m => m.Popularity)
                                    .Take(10)
                                    .ToListAsync();

            var model = new MovieIndex
            {
                MoviesOnCinema    = moviesOnCinema.GetUserMovies(userRates),
                RecommendedMovies = recommendedMovies.GetUserMovies(userRates),
                InterestingMovies = interestingMovies.GetUserMovies(userRates)
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        // GET: Movies
        public ActionResult Index(string movieGenre, string searchString, string searchString2, string sortOrder, string currentFilter, int?page)
        {
            ViewBag.CurrentSort    = sortOrder;
            ViewBag.IDsortParm     = String.IsNullOrEmpty(sortOrder) ? "id" : "";
            ViewBag.TitolsortParm  = sortOrder == "Titol" ? "titol_desc" : "Titol";
            ViewBag.DatasortParm   = sortOrder == "Data" ? "data_desc" : "Data";
            ViewBag.GeneresortParm = sortOrder == "Genere" ? "data_desc" : "Genere";
            ViewBag.PreusortParm   = sortOrder == "Preu" ? "preu_desc" : "Preu";
            ViewBag.IMDBsortParm   = sortOrder == "IMDB" ? "imdb_desc" : "IMDB";
            ViewBag.DuradasortParm = sortOrder == "Durada" ? "durada_desc" : "Durada";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;
            var GenreLst = new List <string>();

            var GenreQry = from d in db.Movies
                           orderby d.Genere
                           select d.Genere;

            GenreLst.AddRange(GenreQry.Distinct());
            ViewBag.movieGenre = new SelectList(GenreLst);

            var movies = from m in db.Movies
                         select m;


            if (!String.IsNullOrEmpty(searchString))
            {
                movies = movies.Where(s => s.Titol.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(searchString2))
            {
                int temp = int.Parse(searchString2);
                movies = movies.Where(i => i.IMDB.Equals(temp));
            }

            if (!string.IsNullOrEmpty(movieGenre))
            {
                movies = movies.Where(x => x.Genere == movieGenre);
            }

            switch (sortOrder)
            {
            case "id":
                movies = movies.OrderByDescending(i => i.ID);
                break;

            case "Titol":
                movies = movies.OrderBy(i => i.Titol);
                break;

            case "titol_desc":
                movies = movies.OrderByDescending(i => i.Titol);
                break;

            case "Data":
                movies = movies.OrderBy(i => i.DataEstrena);
                break;

            case "data_desc":
                movies = movies.OrderByDescending(i => i.DataEstrena);
                break;

            case "Genere":
                movies = movies.OrderBy(i => i.Genere);
                break;

            case "genere_desc":
                movies = movies.OrderByDescending(i => i.Genere);
                break;

            case "Preu":
                movies = movies.OrderBy(i => i.Preu);
                break;

            case "preu_desc":
                movies = movies.OrderByDescending(i => i.Preu);
                break;

            case "IMDB":
                movies = movies.OrderBy(i => i.IMDB);
                break;

            case "IMDB_desc":
                movies = movies.OrderByDescending(i => i.IMDB);
                break;

            case "Durada":
                movies = movies.OrderBy(i => i.Durada);
                break;

            case "durada_desc":
                movies = movies.OrderByDescending(i => i.Durada);
                break;

            default:
                movies = movies.OrderBy(i => i.ID);
                break;
            }

            List <MovieIndex> mv           = new List <MovieIndex>();
            List <Movie>      moviesResult = movies.ToList();

            for (int i = 0; i < moviesResult.Count(); i++)
            {
                var        movieId = moviesResult[i].ID;
                var        copies  = (from c in db.Copies where c.IDmovie == movieId select c).Count();
                MovieIndex mindex  = new MovieIndex
                {
                    ID          = moviesResult[i].ID,
                    IMDB        = moviesResult[i].IMDB,
                    Preu        = moviesResult[i].Preu,
                    Genere      = moviesResult[i].Genere,
                    Sinopsi     = moviesResult[i].Sinopsi,
                    Titol       = moviesResult[i].Titol,
                    Cartell     = moviesResult[i].Cartell,
                    DataEstrena = moviesResult[i].DataEstrena,
                    Durada      = moviesResult[i].Durada,
                    numCopies   = copies
                };
                mv.Add(mindex);
            }

            int pageSize   = 3;
            int pageNumber = (page ?? 1);

            return(View(mv.ToPagedList(pageNumber, pageSize)));
        }