Exemplo n.º 1
0
 private void SaveToDB(IEnumerable <DeviceData> devDataArg, int deviceId)
 {
     try
     {
         logger.Info("Saving to DB ...");
         var readings = new List <Readings>();
         var count    = 0;
         using (MeasurementsDBEntities db = new MeasurementsDBEntities())
         {
             foreach (var data in devDataArg)
             {
                 readings.Add(new Readings
                 {
                     Id                  = Guid.NewGuid(),
                     DeviceId            = deviceId,
                     Value               = data.Value,
                     MeasurementDateTime = data.Date
                 });
                 count++;
             }
             db.Readings.AddRange(readings);
             db.SaveChanges();
         }
         logger.Info($"Data is saved to DB: {count} entry(es).");
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
Exemplo n.º 2
0
 public HomeController()
 {
     db = new MeasurementsDBEntities();
 }