public IActionResult Add([FromBody] Models.SensorData sensorData) { if (sensorData == null) { return(BadRequest()); } _sensorDataService.Add(sensorData); return(Ok()); }
public static void SetProperty(string compoundProperty, object target, String value, String parent, String fullFieldPath) { if (value != "") { string[] bits = compoundProperty.Split('.'); if (parent == "Data") { String[] dataCols = null; dataCols = compoundProperty.Split('\t'); //ignore the header row if (dataCols[1] != "yyyy-MM-dd hh:mm") { PropertyInfo parentProperty = target.GetType().GetProperty("Data"); List <Models.SensorData> childDataObject = (List <Models.SensorData>)parentProperty.GetValue(target, null); Models.SensorData sd = new Models.SensorData(); for (int i = 0; i <= dataCols.Length - 1; i++) { if (i == 1) { //PropertyInfo propertyToSet = childDataObject.GetType().GetProperty("DateTime"); //propertyToSet.SetValue(childDataObject, dataCols[i], null); sd.DateTime = dataCols[i]; } else if (i == 2) { //PropertyInfo propertyToSet = childDataObject.GetType().GetProperty("T"); //propertyToSet.SetValue(childDataObject, dataCols[i], null); sd.T = dataCols[i]; } else if (i == 3) { //PropertyInfo propertyToSet = childDataObject.GetType().GetProperty("OutOfLimits"); //propertyToSet.SetValue(childDataObject, dataCols[i], null); sd.OutOfLimits = dataCols[i]; } } childDataObject.Add(sd); //target.Data.DateTime = dataCols[0]; //PropertyInfo childProperty = parentProperty.GetType().GetProperty("DateTime"); Console.WriteLine("line128"); } //|| fullFieldPath.Contains("Conf.ExtSensor") } else if (fullFieldPath.Contains("Conf.Alarm.Zero.TAL") || fullFieldPath.Contains("Conf.Alarm.One.TAL") || fullFieldPath.Contains("Conf.ExtSensor") || fullFieldPath.Contains("Conf.IntSensor") || fullFieldPath.Contains("Conf.TestRes")) { bits = fullFieldPath.Split('.'); String[] rows = compoundProperty.Split(','); for (int i = 0; i < rows.Length; i++) { object targetTmp = target; for (int j = 0; j < bits.Length - 1; j++) { PropertyInfo propertyToGet = targetTmp.GetType().GetProperty(bits[j]); targetTmp = propertyToGet.GetValue(targetTmp, null); } String[] data = rows[i].Split(':'); PropertyInfo propertyToSet = null; if (rows[i].Contains("T AL")) { propertyToSet = targetTmp.GetType().GetProperty("UpperTAL"); } else if (rows[i].Contains("t AL")) { propertyToSet = targetTmp.GetType().GetProperty("LowerTAL"); } else if (rows[i].Contains("Timeout")) { propertyToSet = targetTmp.GetType().GetProperty("Timeout"); } else if (rows[i].Contains("Offset")) { propertyToSet = targetTmp.GetType().GetProperty("Offset"); } else if (rows[i].Contains("Test Res")) { propertyToSet = targetTmp.GetType().GetProperty("TestRes"); } else if (rows[i].Contains("Test TS")) { propertyToSet = targetTmp.GetType().GetProperty("TestTS"); } if (propertyToSet != null) { if (rows[i].Contains("Test TS")) { propertyToSet.SetValue(targetTmp, data[1] + ":" + data[2], null); } else { propertyToSet.SetValue(targetTmp, data[1], null); } } } Console.WriteLine("line418"); } else { String propertyName = ""; Console.WriteLine("compoundProperty: " + compoundProperty); if (compoundProperty.Contains("Conf.Alarm.Zero.TAL")) { String[] vals = value.Split(','); Console.WriteLine("line417"); } for (int i = 0; i < bits.Length - 1; i++) { if (bits[i] == "Alarm") { Console.WriteLine("line325"); } //propertyName = bits[i].Replace(" ", String.Empty); //propertyName = applyNamingConventionToPropertyName(bits[i]); PropertyInfo propertyToGet = target.GetType().GetProperty(bits[i]); target = propertyToGet.GetValue(target, null); } //propertyName = bits.Last().Replace(" ", String.Empty); //propertyName = applyNamingConventionToPropertyName(bits.Last()); PropertyInfo propertyToSet = target.GetType().GetProperty(bits.Last()); if (propertyToSet != null) { propertyToSet.SetValue(target, value, null); } } } }
public void Add(Models.SensorData item) { _context.SensorData.Add(item); _context.SaveChanges(); }