コード例 #1
0
        public async Task <Trip> SaveCity(int locationId, [FromBody] string[] names) /*First name is city, second name is country, third is place_id*/
        {
            ILocationManager m = ObjectContainer.GetLocationManager();
            Location         l = m.Get(locationId);

            ICityDbProvider c = ObjectContainer.GetCityDbProvider();

            if (names[0] == "" && names[1] == "" && names[2] == null)
            {
                l.City = null;
            }
            else
            {
                l.City = new City
                {
                    Name          = names[0],
                    CountryID     = c.GetCountryByName(names[1]).ID,
                    GooglePlaceId = names[2]
                };
            }

            m.Save(l);

            IMapsManager map  = ObjectContainer.GetMapsManager();
            ITripManager t    = ObjectContainer.GetTripManager();
            Trip         trip = t.Get(l.TripId);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await map.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }
コード例 #2
0
ファイル: MapsController.cs プロジェクト: Penguibird/tieto_be
        public async Task <Country[]> ValidateCountry(string country)
        {
            HttpClient          c   = new HttpClient();
            string              key = System.IO.File.ReadAllText(Path.GetFullPath("~/../Assets/api_key.txt").Replace("~\\", ""));
            HttpResponseMessage m   = await c.GetAsync("https://maps.googleapis.com/maps/api/place/autocomplete/json?language=en&key=" + key + "&types=(regions)&input=" + country);

            string response = await m.Content.ReadAsStringAsync();

            response = FixCountryNames(response);

            ICityDbProvider cityDbProvider = ObjectContainer.GetCityDbProvider();

            CityDT o = Newtonsoft.Json.JsonConvert.DeserializeObject <CityDT>(response);

            List <Country> countries = new List <Country>();

            for (var i = 0; i < o.Predictions.Length; i++)
            {
                var guess = cityDbProvider.GetCountryByName(o.Predictions[i].structured_formatting.main_text);
                if (guess != null && !countries.Contains(guess))
                {
                    countries.Add(guess);
                }
            }

            return(countries.ToArray());
        }
コード例 #3
0
ファイル: MapsController.cs プロジェクト: Penguibird/tieto_be
        public async Task <City[]> ValidateCity(string city)
        {
            HttpClient          c   = new HttpClient();
            string              key = System.IO.File.ReadAllText(Path.GetFullPath("~/../Assets/api_key.txt").Replace("~\\", ""));
            HttpResponseMessage m   = await c.GetAsync("https://maps.googleapis.com/maps/api/place/autocomplete/json?language=en&key=" + key + "&types=(cities)&input=" + city);

            string response = await m.Content.ReadAsStringAsync();

            response = FixCountryNames(response);

            ICityDbProvider cityDbProvider = ObjectContainer.GetCityDbProvider();

            CityDT o = Newtonsoft.Json.JsonConvert.DeserializeObject <CityDT>(response);

            string[] realCities    = new string[o.Predictions.Length];
            string[] secs          = new string[o.Predictions.Length];
            string[] realCountries = new string[o.Predictions.Length];
            City[]   cities        = new City[o.Predictions.Length];

            for (var i = 0; i < o.Predictions.Length; i++)
            {
                realCities[i]    = o.Predictions[i].structured_formatting.main_text;
                secs[i]          = o.Predictions[i].structured_formatting.secondary_text;
                realCountries[i] = (secs[i] == "" || secs[i] == null) ? realCities[i] : secs[i];
                if (realCountries[i].Contains(','))
                {
                    realCountries[i] = realCountries[i].Split(',')[realCountries[i].Split(',').Length - 1];
                }
                if (realCountries[i].ElementAt(0) == ' ')
                {
                    realCountries[i] = realCountries[i].Substring(1);
                }
                cities[i] = new City
                {
                    Country       = cityDbProvider.GetCountryByName(realCountries[i]),
                    GooglePlaceId = o.Predictions[i].place_id,
                    Name          = realCities[i]
                };
            }
            return(cities);
        }