Esempio n. 1
0
 public int QueryZonePassage(int zoneId)
 {
     using var context = new SmartCityZoneContext();
     return(context.ZoneAreas
            .Where(x => x.Sensor.Zone.ZoneId == zoneId)
            .Count());
 }
Esempio n. 2
0
 public AtmData QueryAtmosphere(long atmId)
 {
     using var context = new SmartCityZoneContext();
     return(context.AtmosphereData.ToList()
            .Where(x => x.AtmreadId == atmId)
            .FirstOrDefault());
 }
Esempio n. 3
0
        public void FlushAllData()
        {
            try
            {
                using var context = new SmartCityZoneContext();
                context.Database.EnsureCreated();

                Console.WriteLine("Removing all data from AtmosphereData");
                context.AtmosphereData.RemoveRange(context.AtmosphereData.ToList());
                Console.WriteLine("Removing all data from Sensors");
                context.Sensors.RemoveRange(context.Sensors.ToList());
                Console.WriteLine("Removing all data from SensorTypes");
                context.SensorTypes.RemoveRange(context.SensorTypes.ToList());
                Console.WriteLine("Removing all data from Vehicles");
                context.Vehicles.RemoveRange(context.Vehicles.ToList());
                Console.WriteLine("Removing all data from VehicleRoberies");
                context.VehicleRoberies.RemoveRange(context.VehicleRoberies.ToList());
                Console.WriteLine("Removing all data from Zones");
                context.Zones.RemoveRange(context.Zones.ToList());
                Console.WriteLine("Removing all data from ZoneAreas");
                context.ZoneAreas.RemoveRange(context.ZoneAreas.ToList());
                Console.WriteLine("Removing all data from ZoneParkingRegister");
                context.ZoneParkingRegister.RemoveRange(context.ZoneParkingRegister.ToList());

                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when purging");
                throw e;
            }
        }
Esempio n. 4
0
 public VehicleRoberyData QueryRobery(long roberyId)
 {
     using var context = new SmartCityZoneContext();
     return(context.VehicleRoberies.ToList()
            .Where(x => x.VehicleRoberyId == roberyId)
            .FirstOrDefault());
 }
Esempio n. 5
0
 public int QueryZoneRobery(int zoneId)
 {
     using var context = new SmartCityZoneContext();
     return(context.VehicleRoberies
            .Where(x => x.Zone.ZoneId == zoneId)
            .Count());
 }
Esempio n. 6
0
 public ZoneAreaData QueryZoneArea(long zoneAreaId)
 {
     using var context = new SmartCityZoneContext();
     return(context.ZoneAreas.ToList()
            .Where(x => x.ZoneAreaId == zoneAreaId)
            .FirstOrDefault());
 }
Esempio n. 7
0
        public double QuerySOxDay(DateTime date)
        {
            using var context = new SmartCityZoneContext();
            var aux = context.AtmosphereData.Where(s => s.Date.Date == date.Date).Select(a => a.SOx);

            return(aux.Sum() / aux.Count());
        }
Esempio n. 8
0
 public Vehicle QueryVehicle(long vehicleId)
 {
     using var context = new SmartCityZoneContext();
     return(context.Vehicles.ToList()
            .Where(x => x.VehicleId == vehicleId)
            .FirstOrDefault());
 }
Esempio n. 9
0
 public Sensor QuerySensor(long sensorId)
 {
     using var context = new SmartCityZoneContext();
     return(context.Sensors.ToList()
            .Where(x => x.SensorId == sensorId)
            .FirstOrDefault());
 }
Esempio n. 10
0
        public double QueryCoDay(DateTime date)
        {
            using var context = new SmartCityZoneContext();
            var co = context.AtmosphereData.Where(s => s.Date.Date == date.Date).Select(a => a.CO);

            return(co.Sum() / co.Count());
        }
Esempio n. 11
0
 public ZoneParkingData QueryZoneParking(long zoneParkingId)
 {
     using var context = new SmartCityZoneContext();
     return(context.ZoneParkingRegister.ToList()
            .Where(x => x.ZoneParkingId == zoneParkingId)
            .FirstOrDefault());
 }
Esempio n. 12
0
        public SensorType QuerySensorType(long typeId)
        {
            using var context = new SmartCityZoneContext();

            Random a = new Random();

            return(context.SensorTypes.ToList()
                   .Where(x => x.TypeId == typeId)
                   .FirstOrDefault());
        }
Esempio n. 13
0
 public void InsertRegisterRoberys(List <VehicleRoberyData> roberyList)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.AddRange(roberyList);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering Roberys");
         throw e;
     }
 }
Esempio n. 14
0
 public void InsertRegisterSensor(Sensor sensor)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.Add(sensor);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering a Sensor");
         throw e;
     }
 }
Esempio n. 15
0
 public void InsertRegisterZoneParkings(List <ZoneParkingData> zoneParkingList)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.AddRange(zoneParkingList);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering ZoneParkings");
         throw e;
     }
 }
Esempio n. 16
0
 public void InsertRegisterAtmospheres(List <AtmData> atmList)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.AddRange(atmList);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering AtmDatas");
         throw e;
     }
 }
Esempio n. 17
0
 public void InsertRegisterZoneArea(ZoneAreaData zoneArea)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.Add(zoneArea);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering a ZoneAreaData");
         throw e;
     }
 }
Esempio n. 18
0
 public void InsertRegisterSensorTypes(List <SensorType> sensorTypeList)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.AddRange(sensorTypeList);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering SensorTypes");
         throw e;
     }
 }
Esempio n. 19
0
 public void InsertRegisterVehicle(Vehicle vehicle)
 {
     try
     {
         using var context = new SmartCityZoneContext();
         context.Add(vehicle);
         context.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine("Problem connecting to DB when registering a Vehicle");
         throw e;
     }
 }
Esempio n. 20
0
        public void registerZoneAtm(AtmData zoneAtmDataInfo)
        {
            try
            {
                using var context = new SmartCityZoneContext();

                zoneAtmDataInfo.Sensor = context.Sensors.ToList().Where(x => x.SensorId == zoneAtmDataInfo.Sensor.SensorId).First();

                context.Add(zoneAtmDataInfo);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when registering a Atmosphere reading");
                throw e;
            }
        }
Esempio n. 21
0
        public void registerZonePass(ZoneAreaData zone)
        {
            try
            {
                using var context = new SmartCityZoneContext();

                zone.Vehicle = context.Vehicles.Where(x => x.VehicleId == zone.Vehicle.VehicleId).First();
                zone.Sensor  = context.Sensors.Where(x => x.SensorId == zone.Sensor.SensorId).First();

                context.Add(zone);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when registering a area entry");
                throw e;
            }
        }
        public void registerParkExit(long carRfid)
        {
            try
            {
                using var context = new SmartCityZoneContext();

                var parkingData = context.ZoneParkingRegister
                                  .OrderByDescending(x => x.Date)
                                  .Where(x => x.Vehicle.VehicleId == carRfid)
                                  .FirstOrDefault();
                parkingData.Duration = DateTime.Now - parkingData.Date;

                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when registering a Atmosphere reading");
                throw e;
            }
        }
Esempio n. 23
0
        public void InsertRegisterSensors(List <Sensor> sensorList)
        {
            try
            {
                using var context = new SmartCityZoneContext();

                sensorList = sensorList.Select(x => new Sensor
                {
                    Zone     = context.Zones.Where(y => y.ZoneId == x.Zone.ZoneId).First(),
                    SensorId = x.SensorId,
                    Type     = context.SensorTypes.Where(y => y.TypeId == x.Type.TypeId).First()
                }).ToList();

                context.AddRange(sensorList);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when registering Sensors");
                throw e;
            }
        }
        public void registerParkEntery(ZoneParkingData parkingData)
        {
            try
            {
                using var context = new SmartCityZoneContext();

                parkingData.Vehicle = context.Vehicles
                                      .Where(x => x.VehicleId == parkingData.Vehicle.VehicleId)
                                      .First();
                parkingData.Sensor = context.Sensors
                                     .Where(x => x.SensorId == parkingData.Sensor.SensorId)
                                     .First();

                context.Add(parkingData);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem connecting to DB when registering a Atmosphere reading");
                throw e;
            }
        }
Esempio n. 25
0
 public IEnumerable <Vehicle> QueryVehicleDistinctZoneData()
 {
     using var context = new SmartCityZoneContext();
     return(context.ZoneAreas.Select(s => s.Vehicle).Distinct().ToList());
 }
Esempio n. 26
0
 public List <AtmData> QueryAtmosphereZoneList(int id)
 {
     using var context = new SmartCityZoneContext();
     return(context.AtmosphereData.Where(s => s.Sensor.Zone.ZoneId == id).ToList());
 }
Esempio n. 27
0
 public List <AtmData> QueryAtmosphereList()
 {
     using var context = new SmartCityZoneContext();
     return(context.AtmosphereData.ToList());
 }
Esempio n. 28
0
 public int QueryNumberSensores()
 {
     using var context = new SmartCityZoneContext();
     return(context.Sensors.Distinct().Count());
 }
Esempio n. 29
0
 public List <VehicleRoberyData> QueryGetRoberyList()
 {
     using var context = new SmartCityZoneContext();
     return(context.VehicleRoberies.ToList());
 }
Esempio n. 30
0
 public int QueryNumberRoberys()
 {
     using var context = new SmartCityZoneContext();
     return(context.VehicleRoberies.Count());
 }