public void AddNewNode(AddNewNodeQueryParams parameters)
        {
            GeocodingAddressModelQueryParams address = new GeocodingAddressModelQueryParams(parameters.Street, parameters.DoorNumber, parameters.PostalCode, parameters.County, parameters.District);

            Station stationAdded = new Station();
            //TODO: REFACTOR THIS
            RootGeocodingDataModel <GeocodingAddressResponseModel> coords =
                _geocodingDomain.GetCoordsFromAddress(address);

            Location location = _locationDomain.RetrieveLocation(coords.Data.FirstOrDefault().Latitude,
                                                                 coords.Data.FirstOrDefault().Longitude);

            if (location == null)
            {
                District district = _districtDomain.GetDistrictByDistrictName(address.District);
                County   county   = _countyDomain.GetCountyByCountyName(address.County);
                _locationDomain.InsertLocationData(location, district.Id_District, county.CountyId);
                location = _locationDomain.RetrieveLocation(coords.Data.FirstOrDefault().Latitude,
                                                            coords.Data.FirstOrDefault().Longitude);
            }



            //SE nao for um sensor real procurar a estação metereologica mais proxima, adicionar a bd, e depois adiconar o no a apontar para a estação
            if (parameters.IsRealSensor != true)
            {
                var stationAddedInfo = _weatherStationApplication
                                       .AddWeatherStationToDatabase(address);
                stationAdded =
                    _weatherStationApplication.RetrieveStationByStationName(stationAddedInfo.station.Name);

                Location locationStationAddded = stationAddedInfo.locationStations;

                SmartIrrigationModels.Models.DTOS.Node nodeAdded = _nodeDomain.AddNewNode(parameters, location.Id_Location,
                                                                                          stationAdded.Id_Station ?? -1);

                _weatherStationApplication.AddWeatherStationDataToDatabase(stationAdded, locationStationAddded, nodeAdded);
            }
            else
            {
                //se for um sensor real, adiciona o no com o IdNearStation a -1 e depois adiciona os sensores a apontar para o no No

                _nodeDomain.AddNewNode(parameters, location.Id_Location, -1);

                foreach (var sensor in parameters.SensorsImplemented)
                {
                    _sensorDomain.AddNewSensor(parameters.Street, sensor, location.Id_Location ?? -1);
                }
            }
        }
        public (Station station, Location locationStations) AddWeatherStationToDatabase(GeocodingAddressModelQueryParams parameters)
        {
            #region LocationOfParametersSent

            GeocodingAddressResponseModel locationquerycoords = _geocodingDomain.GetCoordsFromAddress(parameters).Data.FirstOrDefault();
            District district = _districtDomain.GetDistrictByDistrictName(parameters.District);
            County   county   = _countiesDomain.GetCountyByCountyName(parameters.County);

            Location locationquery = new Location(locationquerycoords.Latitude, locationquerycoords.Longitude, "0", locationquerycoords.Name, district.Id_District, county.CountyId);
            _locationDomain.InsertLocationData(locationquery, district.Id_District, county.CountyId);

            WeatherStationWithParamsModel nearbyWeatherStation =
                _weatherStationDomain.FindNearByStationFromLatLong(new FindNearbyStationModel(float.Parse(locationquerycoords.Latitude, CultureInfo.InvariantCulture.NumberFormat),
                                                                                              float.Parse(locationquerycoords.Longitude, CultureInfo.InvariantCulture.NumberFormat), 8, null));

            #endregion LocationOfParametersSent

            //Location id nearbyWeatherStation
            Location locationStation = new Location(nearbyWeatherStation.Latitude.ToString().Replace(',', '.'), nearbyWeatherStation.Longitude.ToString().Replace(',', '.'), nearbyWeatherStation.Elevation.ToString().Replace(',', '.'), nearbyWeatherStation.Name.En, district.Id_District, county.CountyId);

            //Insert if not exists
            _locationDomain.InsertLocationData(locationStation, district.Id_District, county.CountyId);

            //Add Weather station if not exists
            Station stationAdded = new Station(null, nearbyWeatherStation.Name.En, nearbyWeatherStation.Country, nearbyWeatherStation.Region, nearbyWeatherStation.National, nearbyWeatherStation.Wmo, nearbyWeatherStation.Icao, nearbyWeatherStation.Iata, nearbyWeatherStation.Elevation, nearbyWeatherStation.Timezone, nearbyWeatherStation.Active, _locationDomain.RetrieveLocation(nearbyWeatherStation.Latitude.ToString().Replace(',', '.'), nearbyWeatherStation.Longitude.ToString().Replace(',', '.')).Id_Location);
            _weatherStationDomain.AddWeatherStationToDatabase(stationAdded);



            return(stationAdded, locationStation);
        }
 public SmartIrrigationModels.Models.DTOS.Location RetrieveLocation(string latitude, string longitude) =>
 _locationDomain.RetrieveLocation(latitude, longitude);