public CollectorsValues GetIndoorCollectors() { var collectorsValues = new CollectorsValues(); var dashboard = _context.Dashboards.Include(t => t.OutdoorCollector.Sensors) .First(); if (dashboard != null) { // Vnitřní senzory var indoorCollectors = new List <CollectorValues>(); foreach (var collector in _context.Collectors.Where(t => t.Id != dashboard.OutdoorCollector.Id).Include(t => t.Sensors)) { var collectorValues = new CollectorValues(); var indoorSensorValues = new List <SensorValue>(); foreach (var sensor in collector.Sensors) { var sv = new SensorValue(); sv.Sensor = sensor; sv.Value = _context.SensorRecords.Where(t => t.SensorId == sensor.Id).LastOrDefault().Value; indoorSensorValues.Add(sv); } collectorValues.Sensors = indoorSensorValues; collectorValues.Location = collector.Name; indoorCollectors.Add(collectorValues); } collectorsValues.Collectors = indoorCollectors.ToArray(); } return(collectorsValues); }
public CollectorsValues GetOutdoorCollectors() { var collectorsValues = new CollectorsValues(); if (_context.Dashboards.Count() > 0) { var dashboard = _context.Dashboards.Include(t => t.OutdoorCollector.Sensors) .First(); if (dashboard != null) { var outdoorCollectors = new List <CollectorValues>(); var outdoorCollector = dashboard.OutdoorCollector; if (outdoorCollector != null) { var collectorValues = new CollectorValues(); var outdoorSensorValues = new List <SensorValue>(); foreach (var sensor in outdoorCollector.Sensors) { var sv = new SensorValue(); sv.Sensor = sensor; sv.Value = _context.SensorRecords.Where(t => t.SensorId == sensor.Id).LastOrDefault().Value; outdoorSensorValues.Add(sv); } collectorValues.Sensors = outdoorSensorValues; collectorValues.Location = outdoorCollector.Name; outdoorCollectors.Add(collectorValues); } collectorsValues.Collectors = outdoorCollectors.ToArray(); } } return(collectorsValues); }