Пример #1
0
        public async Task <PlaceAttributes> GetPlaceData(string DeparturePlace, string PlaceId)
        {
            try
            {
                //using (HttpClient client = new HttpClient())
                //{
                var client   = _httpClientFactory.CreateClient("GoogleClient");
                Uri endpoint = client.BaseAddress; // Returns GoogleApi
                var Key      = _iconfiguration["GoogleAPI"];
                var Url      = endpoint.ToString() + "maps/api/place/details/json?placeid=" + PlaceId + "&key=" + Key;
                var client1  = _httpClientFactory.CreateClient();
                var response = await client1.GetAsync(Url);

                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                Rootobject             data    = JsonConvert.DeserializeObject <Rootobject>(responseBody);
                PlaceAttributes        Data    = data.result.TransalatePlaceData(Key, endpoint);
                DistanceTimeAttributes Journey = await _getDistanceTime.GetDistanceTime(DeparturePlace, Data.Latitude, Data.Longitude);

                Data.Distance = Journey.Distance;
                Data.Duration = Journey.Duration;
                return(Data);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }
        public async Task <List <PlaceAttributes> > GetFilterData(List <PlaceAttributes> AllData, string DeparturePlace, int LayoverTime, string FilterKey)
        {
            try
            {
                List <PlaceAttributes> FilterData = new List <PlaceAttributes>();
                for (int Index = 0; Index < AllData.Count; Index++)
                {
                    DistanceTimeAttributes Journey = await _getDistanceTime.GetDistanceTime(DeparturePlace, AllData[Index].Latitude, AllData[Index].Longitude);

                    int TotalMinutes = 0;
                    int MinsPosition = Journey.Duration.IndexOf("m");
                    if (Journey.Duration.Contains("hour"))
                    {
                        int HourPosition = Journey.Duration.IndexOf("r");
                        int hour         = Convert.ToInt32(Journey.Duration.Substring(0, Journey.Duration.IndexOf("h")));
                        int min          = Convert.ToInt32(Journey.Duration.Substring(HourPosition + 1, 2));
                        TotalMinutes = (hour * 60) + min;
                    }
                    else
                    {
                        TotalMinutes = Convert.ToInt32(Journey.Duration.Substring(0, MinsPosition));
                    }
                    int CommutingTime = (2 * TotalMinutes) + 60;
                    int IsPossible    = LayoverTime - CommutingTime;
                    if (IsPossible > 0 && LayoverTime >= CommutingTime)
                    {
                        PlaceAttributes data = new PlaceAttributes();
                        data.Name             = AllData[Index].Name;
                        data.Address          = AllData[Index].Address;
                        data.OpenClosedStatus = AllData[Index].OpenClosedStatus;
                        data.Image            = AllData[Index].Image;
                        data.PlaceID          = AllData[Index].PlaceID;
                        data.Rating           = AllData[Index].Rating;
                        data.Vicinity         = AllData[Index].Vicinity;
                        FilterData.Add(data);
                    }
                }
                _allDataExchangethroughRedisCache.SaveInCache(FilterData, FilterKey);
                return(FilterData);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(null);
        }
        public static PlaceAttributes TransalatePlaceData(this Result results, string Key, Uri Url)
        {
            PlaceAttributes PlaceDetails = new PlaceAttributes();

            PlaceDetails.Name             = results.name;
            PlaceDetails.Address          = results.formatted_address;
            PlaceDetails.OpenClosedStatus = results.opening_hours.open_now;
            PlaceDetails.Image            = Url + "maps/api/place/photo?maxwidth=400&photoreference=" + results.photos[0].photo_reference + "&key=" + Key;
            PlaceDetails.PlaceID          = results.place_id;
            PlaceDetails.Rating           = results.rating;
            PlaceDetails.Vicinity         = results.vicinity;
            PlaceDetails.Latitude         = results.geometry.location.lat;
            PlaceDetails.Longitude        = results.geometry.location.lng;
            PlaceDetails.PhoneNumber      = results.formatted_phone_number;
            PlaceDetails.Reviews          = GetReviews(results.reviews);
            PlaceDetails.WeekDaysDetail   = results.opening_hours.weekday_text;//results.reviews == null ? null : results.reviews.ToList(),
            PlaceDetails.GoogleMapUrl     = results.url;
            PlaceDetails.Website          = results.website;
            return(PlaceDetails);
        }
Пример #4
0
        public static List <PlaceAttributes> TransalateData(this Result[] results, string Key, Uri Url)
        {
            List <PlaceAttributes> DataDetails = new List <PlaceAttributes>();

            for (int Index = 0; Index < results.Length; Index++)
            {
                //DataDetails.Add(new PlaceAttributes
                //{
                PlaceAttributes data = new PlaceAttributes();
                data.Name             = results[Index].name ?? results[Index].name;
                data.Address          = results[Index].formatted_address ?? results[Index].formatted_address;
                data.OpenClosedStatus = results[Index].opening_hours == null ? false : results[Index].opening_hours.open_now;
                data.Image            = results[Index].photos == null ? null : Url + "maps/api/place/photo?maxwidth=400&photoreference=" + results[Index].photos[0].photo_reference + "&key=" + Key;
                data.PlaceID          = results[Index].place_id == null ? null : results[Index].place_id;
                data.Rating           = results[Index].rating == 0 ? 0 : results[Index].rating;
                data.Vicinity         = results[Index].vicinity == null ? null : results[Index].vicinity;
                data.Latitude         = results[Index].geometry.location.lat == 0 ? 0 : results[Index].geometry.location.lat;
                data.Longitude        = results[Index].geometry.location.lng == 0 ? 0 : results[Index].geometry.location.lng;
                // WeekDaysDetail = results[Index].opening_hours.weekday_text,//results.reviews == null ? null : results.reviews.ToList(),
                // GoogleMapUrl = results[Index].url,
                //Website = results[Index].website,

                //});
                DataDetails.Add(data);
            }

            //List<DataAttributes> StoreDetails = new List<DataAttributes>();
            //for (var index = 0; index < results.Count; index++)
            //{
            //    DataAttributes store = new DataAttributes();

            //    var resultObject = (JObject)results[index];
            //    store.Name = resultObject["name"].Value<string>();
            //    try{ store.Address = resultObject["formatted_address"].Value<string>();}
            //    catch{ store.Address = "Address Not Available";}

            //    try{ var openingStatus = resultObject["opening_hours"].Value<JObject>();
            //         store.OpenClosedStatus = openingStatus["open_now"].Value<string>();}
            //    catch{store.OpenClosedStatus = "Status Not Available";}

            //    try{ var photos = resultObject["photos"].Value<JArray>();
            //        var photosObject = (JObject)photos[0];
            //        store.PhotoReference = photosObject["photo_reference"].Value<string>();}
            //    catch{ store.PhotoReference = "Reference Not Available";}

            //    try { store.PlaceID = resultObject["place_id"].Value<string>(); }
            //    catch { store.PlaceID = "Place ID is Not Available"; }

            //    try{store.Rating = Convert.ToInt32(resultObject["rating"].Value<string>());}
            //    catch{store.Rating = -1;}

            //    //try{
            //    //    store.AllType = resultObject["types"].Value<JArray>();
            //    //    store.Type = Type;}
            //    //catch{store.Type = Type;}

            //    try{ store.Vicinity = resultObject["vicinity"].Value<string>();}
            //    catch { store.Vicinity = "Not Available"; }
            //    var geometry = resultObject["geometry"].Value<JObject>();
            //    var location = geometry["location"].Value<JObject>();
            //    store.Longitude = location["lng"].Value<string>();
            //    store.Latitude = location["lat"].Value<string>();
            //    StoreDetails.Add(store);
            //}
            return(DataDetails);
        }