//
        // GET: /Film/
        public ActionResult Index(int pNumeroPage)
        {
            if (Request.IsAuthenticated)
            {
                Proprietaire proprio = null;

                HttpContextWrapper httpContextWrapper = new HttpContextWrapper(System.Web.HttpContext.Current);

                if (httpContextWrapper != null && httpContextWrapper.Session["proprietaire"] != null)
                {
                    proprio = (Proprietaire)httpContextWrapper.Session["proprietaire"];
                }

                GestionnaireFilms gestionnaireFilms = new GestionnaireFilms();

                // On retourne les x premières fiches

                //numPage = 1;
                //Session["numeroPage"] = numPage;


                List<Film> listeFiltree = ObtenirListeFilmsFiltree();

                ListeFilmViewModel model = new ListeFilmViewModel();
                model.NbPages = listeFiltree.Count / nbFilmsParPage;
                model.NbResultats = listeFiltree.Count;

                if (model.NbResultats % nbFilmsParPage > 0)
                {
                    model.NbPages++;
                }

                model.ListeFilms = (listeFiltree.Skip((pNumeroPage - 1) * nbFilmsParPage).Take(nbFilmsParPage)).ToList<Film>();

                model.NumeroPage = pNumeroPage;

                //return View(ObtenirListeFilmsFiltree().Skip((numPage-1) * nbFilmsParPage).Take(nbFilmsParPage));
                return View(model);

            }
            else
            {
                return RedirectToAction("LogOn", "Account");
            }
        }
        //public ActionResult Previous()
        //{
        //    if (Request.IsAuthenticated)
        //    {
        //        Proprietaire proprio = null;

        //        HttpContextWrapper httpContextWrapper = new HttpContextWrapper(System.Web.HttpContext.Current);

        //        if (httpContextWrapper != null && httpContextWrapper.Session["proprietaire"] != null)
        //        {
        //            proprio = (Proprietaire)httpContextWrapper.Session["proprietaire"];
        //        }

        //        //GestionnaireFilms gestionnaireFilms = new GestionnaireFilms();

        //        List<Film> listeFilms = ObtenirListeFilmsFiltree();


        //        // On retourne les n premières fiches

        //        numPage = (int)Session["numeroPage"];

        //        if (numPage > 1)
        //        {
        //            numPage--;
        //        }

        //        Session["numeroPage"] = numPage;

        //        return View("Index", listeFilms.Skip((numPage - 1) * nbFilmsParPage).Take(nbFilmsParPage));

        //    }
        //    else
        //    {
        //        return RedirectToAction("LogOn", "Account");
        //    }
        //}


        /// <summary>
        /// Application d'un filtre sur la liste des films
        /// </summary>
        /// <param name="selectedGenres">selectedGenres</param>
        /// <param name="selectedProprietaires">selectedProprietaires</param>
        /// <returns></returns>
        public ActionResult Filtrer(string[] selectedGenres, Guid[] selectedProprietaires, string nomFilm)
        {
            Session["critereNomFilm"] = nomFilm;
            Session["critereSelectedGenres"] = selectedGenres;
            Session["critereSelectedProprietaires"] = selectedProprietaires;

            List<Film> listeFiltree = ObtenirListeFilmsFiltree();

            ListeFilmViewModel model = new ListeFilmViewModel();
            model.NbPages = listeFiltree.Count / nbFilmsParPage;
            model.NbResultats = listeFiltree.Count;

            if (model.NbResultats % nbFilmsParPage > 0)
            {
                model.NbPages++;
            }

            model.ListeFilms = (listeFiltree.Take(nbFilmsParPage)).ToList<Film>();

            return View("Index", model);

        }
        public ActionResult TrierParDateCreation()
        {
            if (Request.IsAuthenticated)
            {

                List<Film> listeFiltree = ObtenirListeFilmsFiltree();

                listeFiltree.Sort((Film f1, Film f2) => DateTime.Compare(f2.DateCreation, f1.DateCreation));

                ListeFilmViewModel model = new ListeFilmViewModel();
                model.NbPages = listeFiltree.Count / nbFilmsParPage;
                model.NbResultats = listeFiltree.Count;

                if (model.NbResultats % nbFilmsParPage > 0)
                {
                    model.NbPages++;
                }

                model.ListeFilms = (listeFiltree.Take(nbFilmsParPage)).ToList<Film>();

                return View("Index", model);

            }
            else
            {
                return RedirectToAction("LogOn", "Account");
            }
        }