Example #1
0
        public IActionResult Comparaison([FromBody] CritereComparateur critere)
        {
            string ville      = critere.ville;
            string dD         = critere.dateDebutReservationl;
            string dF         = critere.dateFinReservation;
            int    etoile     = critere.nombreEtoile;
            int    nbPersonne = critere.nombrePersonne;

            return(Ok(services.Comparateur(ville, dD, dF, etoile, nbPersonne)));
        }
Example #2
0
        public async Task <IActionResult> Comparateur(CritereComparateur c)
        {
            List <CritereReponse> rep;

            //CritereReponse rep;
            offres = new List <CritereReponse>();
            String query = JsonConvert.SerializeObject(c);

            Console.WriteLine(query);
            StringContent content = new StringContent(query, Encoding.UTF8, "application/json");

            Console.WriteLine(content);
            foreach (Agence agence in hosts)
            {
                try
                {
                    Console.WriteLine("Recherche dans " + agence.host + "...");
                    using (var httpClient = new HttpClient())
                    {
                        using (var response = await httpClient.PostAsync(agence.host, content))
                        {
                            string apiResponse = await response.Content.ReadAsStringAsync();

                            Console.WriteLine("\n" + apiResponse);
                            rep = JsonConvert.DeserializeObject <List <CritereReponse> >(apiResponse);
                            rep.ForEach(e => {
                                e.chambres.ForEach(el => {
                                    SaveImage(el.Image, e.nomHotel.Replace(" ", "") + "_" + el.Id);
                                    el.NomChambre += " Proposé par " + agence.name;
                                });
                            });
                            offres.AddRange(rep);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }

            ViewBag.offres = offres;

            return(View("~/Views/Home/Offre.cshtml"));
        }