Пример #1
0
        public JsonResult SensorsLevels(int id)
        {
            var sensorsUpdates = CsvReadWrite.ReadSensorsLevel(@"C:\Users\ASUS\Desktop\WaterLeakDetection\sensorsLevel.txt");

            foreach (var item in sensorsUpdates)
            {
                var sensor = sensorRepository.GetSensorById(item.Id);
                var leakDB = leakRepository.GetLastLeak(sensor);
                sensor.CurrentLevel = item.CurrentLevel;
                var leakState = leakDB != null ? leakDB.IsRepared : true;
                if (sensor.CurrentLevel > 200)
                {
                    sensor.Count += 1;
                }
                if (sensor.CurrentLevel < 200 && leakState)
                {
                    sensor.Count = 0;
                }
                if (sensor.CurrentLevel < 200 && leakState)
                {
                    sensor.Count -= 1;
                }
                System.Diagnostics.Debug.WriteLine(sensor.Count);



                if (sensor.Count == -1 && leakState && leakDB != null)
                {
                    leakDB.IsRepared = true;
                    leakRepository.Update(leakDB);
                    sensor.Count = 0;
                }
                if (sensor.Count == 1)
                {
                    var leak = new Leak {
                        Sensor = sensor, OccurrenceDate = DateTime.Now
                    };
                    leakRepository.Add(leak);
                    sensor.Count = 0;
                    string subjet   = "New Leak";
                    string body     = string.Format("New leak has been occured .\n Sensor : {0}", sensor.Name);
                    string addresse = "*****@*****.**";
                    SendEmail(addresse, subjet, body);
                    System.Diagnostics.Debug.WriteLine("email sent");
                }

                sensorRepository.update(sensor);
            }
            var departement = departementRepository.GetDepartementById(id);
            var sensors     = sensorRepository.GetAllDepartementSensors(departement);
            var json        = JsonConvert.SerializeObject(sensors);

            return(Json(json));
        }
Пример #2
0
        public ActionResult Details(int id)
        {
            var departement = departementRepository.GetDepartementById(id);

            if (departement != null)
            {
                var sensors = sensorRepository.GetAllDepartementSensors(departement);
                var departementViewModel = GetDepartementViewModel();
                departementViewModel.Departement = departement;
                departementViewModel.Sensors     = sensors;
                return(View(departementViewModel));
            }
            return(RedirectToAction("Index"));
        }