public async Task <bool> UpdateGeolocation(DeviceGeolocationUpdateModel updateGeolocationObj) { RestRequest request = await PrepareQuery("Devices/DeviceLocation", Method.PUT); request.AddParameter("application/json", JsonConvert.SerializeObject(updateGeolocationObj), ParameterType.RequestBody); var queryResult = await _client.ExecuteTaskAsync(request); if (!queryResult.IsSuccessful) { _logger.LogError($"UpdateGeolocation: Error while updating device geolocation: {queryResult.StatusCode}"); return(false); } return(true); }
public async Task <IActionResult> UpdateMobileGeolocation([FromBody] DeviceGeolocationUpdateModel updateGeolocationObj) { string userId = UserHelper.GetBestClaimValue(User.Claims.ToList(), _config.ClaimsId, true).ToLower(); //Update device location DeviceGeolocationUpdateResultModel resultDevice = await _devicesDataManager.UpdateMobileGeolocation(updateGeolocationObj.Geolocation, userId); if (resultDevice == null || !resultDevice.Success) //Error { return(StatusCode(StatusCodes.Status500InternalServerError)); } if (resultDevice.Device == null) //No device update { return(Ok()); } //Send device update if (_serviceBus != null && _serviceBus.BusAccess != null) { //We need to notify the frontend about the change, but it doesn't fit in the device workflow as phones aren't actual iot devices. await _serviceBus.BusAccess.Publish(new DeviceUIUpdateRequestedEvent() { CorrelationId = resultDevice.Device.DeviceId, DeviceUI = new DeviceUIModel() { DeviceId = resultDevice.Device.DeviceId, Device = resultDevice.Device, UpdateType = "UpdateDevice" } }); } //Update active cluster location, if any EventClusterGeolocationUpdateResultModel resultEventCluster = await _eventClustersDataManager .UpdateGeolocation(updateGeolocationObj.Geolocation, resultDevice.Device.DeviceId); if (resultEventCluster == null || !resultEventCluster.Success) //Error { return(StatusCode(StatusCodes.Status500InternalServerError)); } if (resultEventCluster.EventCluster == null) { return(Ok()); } //Send event cluster update if (_serviceBus != null && _serviceBus.BusAccess != null) { //We need to notify the frontend about the change await _serviceBus.BusAccess.Publish(new EventUIUpdateRequestedEvent() { CorrelationId = resultEventCluster.EventCluster.Device.DeviceId, EventClusterUI = new EventClusterUIModel() { EventCluster = resultEventCluster.EventCluster, UpdateType = "UpdateEventCluster" } }); } return(Ok()); }