public async Task PostMeasurement(string Mac, string data) { Box box = _context.Boxes.FirstOrDefault(b => b.MacAddress == Mac); if (box == null) { return; } DateTime date1 = DateTime.UtcNow; TimeZoneInfo timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); DateTime date2 = TimeZoneInfo.ConvertTime(date1, timeZoneInfo); List <string> dummy = HexHelper.HexConv(data); if (int.Parse(dummy[0]) == 1) { dummy.Remove("1"); dummy.RemoveAll(p => p == "0"); string test = string.Join(",", dummy); box.ConfiguratieString = test; await _context.SaveChangesAsync(); return; } if (int.Parse(dummy[0]) == 2) { dummy.Remove("2"); //string test = string.Join(",", dummy); //string[] values = test.Split(","); string conf = box.ConfiguratieString; string[] sensors = conf.Split(","); int i = 0; foreach (string sensor in sensors) { int sensorid = int.Parse(sensor); SensorBox sensorBox = _context.SensorBoxes.Where(s => s.BoxID == box.BoxID).FirstOrDefault(s => s.SensorID == sensorid); Sensor sensor1 = _context.Sensors.FirstOrDefault(s => s.SensorID == sensorid); if (sensorBox == null) { SensorBox sensorBox1 = new SensorBox(); sensorBox1.BoxID = box.BoxID; sensorBox1.SensorID = sensorid; _context.SensorBoxes.Add(sensorBox1); await _context.SaveChangesAsync(); } Measurement measurement = new Measurement(); measurement.BoxID = box.BoxID; measurement.SensorID = sensorid; measurement.TimeStamp = date2; if (sensor1.SensorTypeID == 4) { int value = int.Parse(dummy[i]) - 100; measurement.Value = value.ToString(); } else { measurement.Value = dummy[i]; } i++; _context.Measurements.Add(measurement); await _context.SaveChangesAsync(); } return; } }