public List <UserGroup> LoadActives()
        {
            List <UserGroup> listRegiones = new List <UserGroup>();

            using (var avlClient = new AvlSoapClient())
            {
                DataTable avlResponse = avlClient.ObtenerRegionesActuales(6, string.Empty);

                if (avlResponse.Rows.Count > 0)
                {
                    foreach (DataRow item in avlResponse.Rows)
                    {
                        listRegiones.Add(new UserGroup()
                        {
                            ID      = int.Parse(item.ItemArray[0].ToString()),
                            Name    = item.ItemArray[1].ToString(),
                            Deleted = false,
                            Active  = true
                        });
                    }
                }
            }

            return(listRegiones);
        }
Exemple #2
0
        private static List <int> GetRegionId(UserMobileModel value, ref double latitude, ref double longitude)
        {
            List <int> listRegiones = new List <int>();

            try
            {
                string URL           = Settings.GoogleMapsAPIURL;
                string urlParameters = $"?address={value.Address}, Suncheles, Santa Fe, Argentina&sensor=false&key={Settings.GoogleMapsAPIKey}";

                HttpClient client = new HttpClient {
                    BaseAddress = new Uri(URL)
                };

                // Add an Accept header for JSON format.
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                // List data response.
                HttpResponseMessage response = client.GetAsync(urlParameters).Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
                if (response.IsSuccessStatusCode)
                {
                    XmlSerializer   serializer       = new XmlSerializer(typeof(GeocodeResponse));
                    GeocodeResponse resultingMessage = (GeocodeResponse)serializer.Deserialize(new XmlTextReader(response.Content.ReadAsStreamAsync().Result));

                    if (Settings.IsDev)
                    {
                        latitude  = double.Parse(resultingMessage.Result.Geometry.Location.Lat.Replace('.', ','));
                        longitude = double.Parse(resultingMessage.Result.Geometry.Location.Lng.Replace('.', ','));
                    }
                    else
                    {
                        latitude  = double.Parse(resultingMessage.Result.Geometry.Location.Lat);
                        longitude = double.Parse(resultingMessage.Result.Geometry.Location.Lng);
                    }

                    if (latitude == Settings.ExcludeLatitude && longitude == Settings.ExcludeLongitude)
                    {
                        listRegiones.Clear();
                        listRegiones.Add(0);
                        return(listRegiones);
                    }

                    //Consulta a la API de AVL la región a la que pertenecen las coordenadas
                    AvlSoapClient avlClient   = new AvlSoapClient();
                    var           avlResponse = avlClient.ObtenerRegionesActualesPorCoordenada(6, latitude, longitude);

                    if (avlResponse.Rows.Count > 0)
                    {
                        foreach (DataRow item in avlResponse.Rows)
                        {
                            if (int.TryParse(item.ItemArray[0].ToString(), out int regionId))
                            {
                                if (item.ItemArray[1].ToString().ToUpper().Contains("RECOLECCI"))
                                {
                                    regionId = regionId * 10000;
                                }
                            }

                            listRegiones.Add(regionId);
                        }
                    }
                }
                else
                {
                    listRegiones.Clear();
                    listRegiones.Add(0);
                    return(listRegiones);
                }

                client.Dispose();
            }
            catch (Exception ex)
            {
                listRegiones.Clear();
                listRegiones.Add(0);
                return(listRegiones);
            }

            return(listRegiones);
        }