/// <summary>
        /// Get the list of devices in a specific radius
        /// </summary>
        /// <param name="deviceGeolocationObj">DeviceGeolocationModel</param>
        /// <returns>List of device ids</returns>
        public async Task <IEnumerable <Guid> > GetDevicesInRadius(DeviceGeolocationModel deviceGeolocationObj)
        {
            IEnumerable <DeviceDAO> devices = await _repoDevices.GetItemsAsync(
                p => p.Enabled && ((!string.IsNullOrEmpty(deviceGeolocationObj.DeviceType) && p.DeviceType.ToLower() == deviceGeolocationObj.DeviceType.ToLower()) ||
                                   (string.IsNullOrEmpty(deviceGeolocationObj.DeviceType))),
                p => new DeviceDAO()
            {
                Id          = p.Id,
                Geolocation = p.Geolocation
            }
                );

            List <Guid>          output = new List <Guid>();
            GeolocationDAOObject daoGeocodeCenterPoint = _mapper.Map <GeolocationDAOObject>(deviceGeolocationObj.ResponseGeolocationPointLocation);

            if (devices != null)
            {
                foreach (DeviceDAO deviceObj in devices)
                {
                    if (deviceObj.Geolocation != null)
                    {
                        if (RadiusHelper.IsWithinRadius(deviceObj.Geolocation, daoGeocodeCenterPoint, deviceGeolocationObj.Radius))
                        {
                            output.Add(new Guid(deviceObj.Id));
                        }
                    }
                }
            }
            return(output);
        }
        public async Task <IEnumerable <Guid> > GetDevicesInRadius(DeviceGeolocationModel deviceGeocodeCenterUpdate)
        {
            RestRequest request = await PrepareQuery("Devices/Radius", Method.POST);

            request.AddParameter("application/json", JsonConvert.SerializeObject(deviceGeocodeCenterUpdate), ParameterType.RequestBody);
            var queryResult = await _client.ExecuteTaskAsync <IEnumerable <Guid> >(request);

            if (queryResult.IsSuccessful)
            {
                return(queryResult.Data);
            }
            else
            {
                _logger.LogError($"GetDevicesInRadius: Error while adding an event: {queryResult.StatusCode}");
            }
            return(null);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetDevicesInRadius([FromBody] DeviceGeolocationModel deviceGeolocationObj)
        {
            IEnumerable <Guid> deviceIds = await _devicesDataManager.GetDevicesInRadius(deviceGeolocationObj);

            return(Ok(deviceIds));
        }