Ejemplo n.º 1
0
 public async Task<IHttpActionResult> PostSensorReading()
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     dynamic obj = await Request.Content.ReadAsAsync<JObject>();
     var dt = DateTime.Now;
     SensorReading sensorReading = new SensorReading();
     int numReadings = (int)obj["numReadings"];
     sensorReading.timeLogged = dt;
     sensorReading.duration = (int)obj["duration"];
     sensorReading.deviceID = (int) obj["deviceID"];
     db.SensorReadings.Add(sensorReading);
     db.SaveChanges();
     JArray types = obj["readingType"];
     JArray values = obj["readingValue"];
     for(int i = 0; i < numReadings; i++)
     {
         SensorReadingValue value = new SensorReadingValue();
         value.sensorReadingID = sensorReading.ID;
         value.readingValueType = (int) types[i];
         value.readingValue = (string) values[i];
         db.SensorReadingValues.Add(value);
     }
     db.SaveChanges();
     return CreatedAtRoute("ControllerAndAction", new { id = sensorReading.ID }, sensorReading);
 }
Ejemplo n.º 2
0
        public IHttpActionResult GetSensorReading(SensorReading sensorReading)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dt = DateTime.Now;
            sensorReading.timeLogged = dt;
            db.SensorReadings.Add(sensorReading);
            db.SaveChanges();

            return CreatedAtRoute("ControllerAndAction", new { id = sensorReading.ID }, sensorReading);
        }