示例#1
0
        public async Task <IActionResult> Add([FromBody] SensorDataModel model)
        {
            List <Wifi> wifis = new List <Wifi>();

            foreach (var item in model.s.wifi)
            {
                wifis.Add(new Wifi {
                    MacAddress = item.Key, RSSI = item.Value
                });
            }

            var sensorData = new SensorData()
            {
                Device = model.d,
                Family = model.f,
                GPS    = new Gps()
                {
                    Altitude  = model.gps["alt"],
                    Latitude  = model.gps["lat"],
                    Longitude = model.gps["lon"]
                },
                Wifis = wifis,
                Date  = UnixTimeStampToDateTime(model.t)
            };

            _repository.Add(sensorData);

            await _repository.UnitOfWork.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = sensorData.Id }, null));
        }
示例#2
0
        private void ListenerMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            if (SensorData.TryParse(e.Message, out var result))
            {
                repository.Add(result);

                Console.WriteLine(e.Message);
            }
        }