Example #1
0
        public void AddSensor(Object obj)
        {
            if (SelectedStatus == "Active")
            {
                CurrentSensor.Status = true;
            }
            else
            {
                CurrentSensor.Status = false;
            }

            service.Add(CurrentSensor);
            Messenger.Default.Send(CurrentSensor);
            new NavService().NavigateTo("Sensors");
        }
Example #2
0
        public async Task <IActionResult> Create([FromBody] DeviceMetadata deviceMetadata)
        {
            if (deviceMetadata == null)
            {
                return(BadRequest());
            }

            var result = await _sensorService.Add(deviceMetadata);

            if (result)
            {
                return(CreatedAtRoute("GetSensor", new { deviceId = deviceMetadata.DeviceId }, deviceMetadata));
            }
            return(BadRequest());
        }
        private async Task <Device> GetOrCreateSensor(int deviceId)
        {
            _logger.LogDebug("Find device with id {deviceId}", deviceId);
            var metadata = await _sensorService.Get(deviceId);

            if (metadata == null)
            {
                metadata = new DeviceMetadata {
                    DeviceId = deviceId
                };
                _logger.LogInformation("Saving device {deviceId}", deviceId);
                var result = await _sensorService.Add(metadata);

                if (!result)
                {
                    _logger.LogError("Failed saving device {deviceId}", deviceId);
                    throw new Exception("Unable to add sensor");
                }
                _logger.LogInformation("Device {deviceId} saved", deviceId);
            }
            var device = new Device(metadata);

            return(device);
        }
Example #4
0
 public IHttpActionResult Post(Sensor sensor)
 {
     return(Ok(_sensorService.Add(sensor)));
 }