Esempio n. 1
0
        public ActionResult Liste(int?page)
        {
            page = page ?? 0;
            //TODO : Return uniquement les projets dont la dateDepart est pas dépassée
            IQueryable <IProjet> completeList = ProjetBasicList();
            //IQueryable<IProjet> nonOutdated = Data.ProjetDataAccess.GetAllProjets().ProjetsNonOutdated().OrderBy(p => p.DateDebut);
            //if(nonOutdated.Count() > 5)

            PagedList <IProjet> projList = new PagedList <IProjet>(completeList, page.Value, NB_PROJETS_PAR_PAGE_LISTE);

            if (projList.Count() < 1)
            {
                string errorMsg = "La page {0} n'existe pas.".FormatWith(page);

                string redirectUrl = Url.RouteUrl(CovCake.Routes.PROJETLIST, new { page = 0 });
                return(ErrorRedirect(errorMsg, 8, redirectUrl));
            }

            ListeProjetViewData projets = new ListeProjetViewData()
            {
                ListeProjets = projList
            };

            if (TempData.ContainsKey("noresult"))
            {
                ViewData["noresult"] = TempData["noresult"];
            }

            return(View(projets));
        }
Esempio n. 2
0
        public ActionResult GetRelatedProjets(SearchProjetParams searchParams, int?page)
        {
            //TODO: Doit utiliser le meme systeme de recherche ke pour les listes

            const int offsetDaysDate  = 20;
            const int offsetDaysJours = 15;

            IQueryable <IProjet> completeList;

            completeList = Data.ProjetDataAccess.GetAllProjets();
            int?     paysId     = searchParams.paysArriveId;
            DateTime?dateDepart = searchParams.dateDebut;
            int      nbJours    = searchParams.nbJours ?? 0;

            page = (page >= 0) ? page : 0;

            if (paysId != null)
            {
                completeList = completeList.ProjetsTo(paysId.Value).Where(p => p.OwnerUserId != this.CurrentUserId);
            }

            if (dateDepart != null)
            {   //TODO: verifier que le projet n'est pas complet ou deja réalisé
                completeList = completeList
                               .ProjetsBetween(dateDepart.Value.AddDays(-offsetDaysDate), dateDepart.Value.AddDays(offsetDaysDate));
                //.Where(p => p.PaysArriveEntity.LibellePays.ToLower().Contains(query))
            }
            else if (nbJours > 0)
            {
                //Inclus les projets incertains
                completeList = completeList //Data.ProjetDataAccess.GetAllProjets()
                                            //.Where(p => p.PaysArrive.LibellePays.ToLower().Contains(query)
                               .Where(p => nbJours - offsetDaysJours <= p.NbJours && p.NbJours <= nbJours + offsetDaysJours);
            }

            ListeProjetViewData relatedProjViewData = new ListeProjetViewData()
            {
                IsSearchResults = true,
                ListeProjets    = completeList.ToPagedList(page.Value, NB_PROJETS_PAR_PAGE_LISTE),
                SearchParams    = searchParams
            };

            return(PartialView("RelatedProjetsList", relatedProjViewData));
        }
Esempio n. 3
0
        public ActionResult Search(SearchProjetParams searchArgs, int?page)
        {
            const int offsetDaysDate  = 10;
            const int offsetDaysJours = 5;

            try
            {
                this.ModelState.Clear();
                page = page ?? 0;
                page = (page >= 0) ? page : 0;

                searchArgs.paysArrive = searchArgs.paysArrive.Trim();
                this.SetPageTitle("Voyages vers " + searchArgs.paysArrive);

                string query = searchArgs.paysArrive;
                if (string.IsNullOrEmpty(query))
                {
                    searchArgs.paysArrive = "~Tous~";
                }
                else if (searchArgs.nbJours != null && (searchArgs.nbJours < 1 || searchArgs.nbJours > 365))
                {
                    this.ModelState.AddModelError("_FORM", "Le nombre de jour doit être compris entre 1 et 365");
                }


                //   searchArgs.paysArrive = searchArgs.paysArrive.ToTitleCase();
                IQueryable <IProjet> completeList;

                //TODO: Faire une recherche en enlevant les accents
                IPays pays = Data.PaysDataAccess.GetPaysFr(query);
                // pays = Data.PaysDataAccess.GetPaysFrNoAccent(query);
                if (!string.IsNullOrEmpty(query) && pays == null)
                {
                    ModelState.AddModelError("_FORM", "Aucun voyages ne concerne ce pays");
                    //TempData["noresult"] = true;
                    //return RedirectToAction("Liste");
                }
                if (ModelState.IsValid)
                {
                    int nbJours = searchArgs.nbJours ?? 0;
                    //TODO: pas comprendre sa...
                    DateTime?dateDepart = searchArgs.dateDebut; //(searchArgs.dateDebut.HasValue) ? searchArgs.dateDebut.Value.AddDays(nbJours) as DateTime? : null;

                    // IQueryable< IPays> pays = Data.PaysDataAccess.GetAllPays().Where(p => p.LibellePays.ToLower().Contains(query));

                    completeList = Data.ProjetDataAccess.GetAllProjets();
                    if (pays != null)
                    {
                        completeList = completeList.ProjetsTo(pays.IdPays);
                    }

                    if (dateDepart != null)
                    {   //TODO: verifier que le projet n'est pas complet ou deja réalisé
                        completeList = completeList
                                       .ProjetsDateDebutBetween(dateDepart.Value.AddDays(-offsetDaysDate), dateDepart.Value.AddDays(offsetDaysDate));
                        //.Where(p => p.PaysArriveEntity.LibellePays.ToLower().Contains(query))
                    }
                    if (nbJours > 0)
                    {
                        //Inclus les projets incertains
                        completeList = completeList //Data.ProjetDataAccess.GetAllProjets()
                                                    //.Where(p => p.PaysArrive.LibellePays.ToLower().Contains(query)
                                       .Where(p => nbJours - offsetDaysJours <= p.NbJours && p.NbJours <= nbJours + offsetDaysJours);
                    }

                    completeList = completeList.OrderBy(p => p.DateDebut);
                    //IQueryable<IProjet> nonOutdated = Data.ProjetDataAccess.GetAllProjets().ProjetsNonOutdated().OrderBy(p => p.DateDebut);
                    //if(nonOutdated.Count() > 5)
                    if (completeList.Count() == 0)
                    {
                        //Afficher tout ls voyage si aucune réponse na été trouvée
                        completeList         = ProjetBasicList();
                        ViewData["noresult"] = true;
                        TempData["noresult"] = true;
                        //return RedirectToAction("Liste");
                    }

                    ListeProjetViewData projets = new ListeProjetViewData()
                    {
                        ListeProjets    = completeList.ToPagedList(page.Value, NB_PROJETS_PAR_PAGE_LISTE),
                        IsSearchResults = true,
                        SearchParams    = searchArgs
                    };



                    return(View("Liste", projets));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("_FORM", "Une erreur est apparue lors de votre recherche");
            }


            ListeProjetViewData basicListeProjets = new ListeProjetViewData()
            {
                ListeProjets    = ProjetBasicList().ToPagedList(page.Value, NB_PROJETS_PAR_PAGE_LISTE),
                IsSearchResults = true,
                SubstituteListe = true,
                SearchParams    = searchArgs
            };

            return(View("Liste", basicListeProjets));//(ListeProjetsViewData)ViewData.Model);
        }