public ActionResult Planvalidation(String from_date, String to_date, String location1, String location2, String nature, String city, String outdoor)
        {
            Planvalidation Plan = new Planvalidation();

            Plan.from_date = from_date;
            Plan.to_date   = to_date;
            Plan.location1 = location1;
            Plan.location2 = location2;
            Plan.nature    = nature;
            Plan.city      = city;
            Plan.outdoor   = outdoor;

            /*go to DB to write variables if those are correct ----must go to trending page*/

            if (!String.IsNullOrEmpty(Plan.location1) && !String.IsNullOrEmpty(Plan.location2))
            {
                return(View("Plan"));
            }
            else
            {
                return(View("Plan"));
            }
        }
Example #2
0
        public ActionResult GetAPIData(String from_date,
                                       String to_date,
                                       String location1,
                                       String location2,
                                       String nature,
                                       String city,
                                       String outdoor)
        {
            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Add("X-Api-Key", key);

            httpClient.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            string URL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=%27" + location2 + "%27+point+of+interest&language=en&key=" + key;

            string Google_Path   = URL;
            string parksdata     = "";
            string nextpagetoken = "";
            Root   parks         = null; // Creating object Parks (From Model).

            //Dictionary<string, object> response_parse;
            //Dictionary<string, object> parksdata;



            httpClient.BaseAddress = new Uri(Google_Path);
            List <Root> FinalResult = new List <Root>();

            // Root[] FinalResult = new Root[5];  // Try linked List

            try
            {
                Planvalidation Plan = new Planvalidation();
                Plan.from_date = from_date;
                Plan.to_date   = to_date;
                Plan.location1 = location1;
                Plan.location2 = location2;
                Plan.nature    = nature;
                Plan.city      = city;
                Plan.outdoor   = outdoor;

                /*go to DB to write variables if those are correct ----must go to trending page*/

                if (!String.IsNullOrEmpty(Plan.location1) && !String.IsNullOrEmpty(Plan.location2))
                {
                    HttpResponseMessage response = httpClient.GetAsync(Google_Path).GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        // Asynchronous for wait till get result, common for remote operation
                        parksdata = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                    }

                    if (!parksdata.Equals(""))
                    {
                        // Deserialize parksdata string into the Parks Object.
                        //parks = JsonConvert.DeserializeObject<Root>(parksdata);
                        //response_parse = JsonConvert.DeserializeObject<Dictionary<string, object>>(Convert.ToString(parksdata));

                        while (true)
                        {
                            parksdata = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                            parks     = JsonConvert.DeserializeObject <Root>(parksdata);
                            FinalResult.Add(parks);


                            object has_next_page = parks.GetType().GetProperty("next_page_token");
                            if (!has_next_page.Equals("") || has_next_page is null) /// Check how to handle Null, should we use is null while comparing string null (actual NULL)?? .
                            {
                                Console.WriteLine("the value is:" + has_next_page);
                                break;
                            }
                            else
                            {
                                nextpagetoken = Convert.ToString(parks.next_page_token);
                                string URL_Copy  = URL;
                                string URL_Final = URL_Copy + "&pagetoken=" + nextpagetoken;
                                response = httpClient.GetAsync(URL_Final).GetAwaiter().GetResult();
                            }
                        }
                    }
                    ViewBag.TopAttraction = "Top Attraction in " + Plan.location2;
                    return(View(FinalResult));
                }
                else
                {
                    return(View("Plan"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(null);
        }
        public ActionResult Plan(String user1, String password1, String destination)
        {
            List <Root> FinalResult = new List <Root>();

            ViewBag.User = user1;
            DataTable     dt = new DataTable();
            List <object> iData_Attraction = new List <object>();
            List <object> iData_Rating     = new List <object>();

            var list = (from cust in dbContext.saveSearch
                        where cust.users.Equals(user1)
                        group cust by cust.destination
                        into grp
                        select new
            {
                destination = grp.Key,
                Count = grp.Count()
            }).ToList();


            if (!String.IsNullOrEmpty(user1) && !String.IsNullOrEmpty(password1) && password1 != "")
            {
                Console.WriteLine("Inside Login Call " + user1);
                Console.WriteLine("user1 " + user1);
                Console.WriteLine("usedestinationr1 " + destination);

                int usrCount =
                    (from usr in dbContext.Usr_login
                     where usr.usr_id.Equals(user1) && usr.pass.Equals(password1)
                     select usr).Count();
                if (usrCount == 0)
                {
                    ViewBag.MandatoryCheck = "Please enter valid UserName and Password.";
                    return(View("Index"));
                }
                else
                {
                    ViewBag.rep = JsonConvert.SerializeObject(list.Select(x => x.Count));
                    ViewBag.hod = JsonConvert.SerializeObject(list.Select(x => x.destination));

                    return(View(FinalResult));
                }
            }

            httpClient = new HttpClient();
            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Add("X-Api-Key", key);

            saveSearch save = new saveSearch();

            save.users       = user1;
            save.destination = destination;
            dbContext.Add(save);
            dbContext.SaveChanges();

            httpClient.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            string URL = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=%27" + destination + "%27+point+of+interest&language=en&key=" + key;

            string Google_Path   = URL;
            string parksdata     = "";
            string nextpagetoken = "";
            Root   parks         = null;

            httpClient.BaseAddress = new Uri(Google_Path);
            try
            {
                Planvalidation Plan = new Planvalidation();
                Plan.location2 = destination;
                if (!String.IsNullOrEmpty(Plan.location2))
                {
                    HttpResponseMessage response = httpClient.GetAsync(Google_Path).GetAwaiter().GetResult();
                    if (response.IsSuccessStatusCode)
                    {
                        // Asynchronous for wait till get result, common for remote operation
                        parksdata = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                    }

                    if (!parksdata.Equals(""))
                    {
                        // Deserialize parksdata string into the Parks Object.
                        //parks = JsonConvert.DeserializeObject<Root>(parksdata);
                        //response_parse = JsonConvert.DeserializeObject<Dictionary<string, object>>(Convert.ToString(parksdata));

                        while (true)
                        {
                            parksdata = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                            parks     = JsonConvert.DeserializeObject <Root>(parksdata);
                            FinalResult.Add(parks);

                            object has_next_page = parks.GetType().GetProperty("next_page_token");
                            if (!has_next_page.Equals("") || has_next_page is null)     /// Check how to handle Null, should we use === while comparing string null (actual NULL)?? .
                            {
                                Console.WriteLine("the value is:" + has_next_page);
                                break;
                            }
                            else
                            {
                                nextpagetoken = Convert.ToString(parks.next_page_token);
                                string URL_Copy  = URL;
                                string URL_Final = URL_Copy + "&pagetoken=" + nextpagetoken;
                                response = httpClient.GetAsync(URL_Final).GetAwaiter().GetResult();
                            }
                        }
                    }
                    ViewBag.TopAttraction = "Top Attraction in " + Plan.location2;



                    foreach (APIproject.Models.Root p in FinalResult)
                    {
                        foreach (ResultsItem r in p.results)
                        {
                            iData_Attraction.Add(r.name);
                        }
                    }

                    var json_Attraction = JsonConvert.SerializeObject(iData_Attraction);
                    Console.WriteLine("json_Attraction " + json_Attraction);
                    ViewBag.iData_Attraction = json_Attraction;

                    foreach (APIproject.Models.Root p in FinalResult)
                    {
                        foreach (ResultsItem r in p.results)
                        {
                            iData_Rating.Add(r.user_ratings_total);
                        }
                    }
                    var json_Rating = JsonConvert.SerializeObject(iData_Rating);
                    Console.WriteLine("json_Rating " + json_Rating);
                    ViewBag.iData_Rating = json_Rating;

                    list = (from cust in dbContext.saveSearch
                            where cust.users.Equals(user1)
                            group cust by cust.destination
                            into grp
                            select new
                    {
                        destination = grp.Key,
                        Count = grp.Count()
                    }).ToList();

                    ViewBag.rep = JsonConvert.SerializeObject(list.Select(x => x.Count));
                    ViewBag.hod = JsonConvert.SerializeObject(list.Select(x => x.destination));


                    return(View(FinalResult));
                }
                else
                {
                    return(View(FinalResult));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }



            return(View(FinalResult));
        }