Example #1
0
 // GET: Sensor/Create
 public ActionResult Create(int?number)
 {
     Models.Sensor sensor = new Models.Sensor {
         SiteID = (int)number
     };
     return(View("Create", sensor));
 }
Example #2
0
        public async void Can_post_items()
        {
            using (_context)
            {
                SensorsController controller      = new SensorsController(_context);
                RoomsController   roomsController = new RoomsController(_context);

                var room     = roomsController.GetRoom();
                var RoomList = new List <Room>();

                foreach (Room data1 in room.Result.Value.ToList())
                {
                    RoomList.Add(data1);
                }

                Models.Sensor testdata = new Models.Sensor();
                testdata.servoSetting = "5";
                testdata.roomID       = RoomList[0].roomID;
                await controller.PostSensor(testdata);

                var sensor    = controller.GetSensor();
                var List      = new List <Sensor>();
                int Listcount = 0;
                foreach (var sensor1 in sensor.Result.Value.ToList())
                {
                    List.Add(sensor1);
                    Listcount++;
                }

                Assert.AreEqual(Listcount, List.Count);
                Assert.AreEqual("5", List[Listcount - 1].servoSetting);

                //Delete

                if (List.Count > 0)
                {
                    var item = List[List.Count - 1];

                    await controller.DeleteSensor(item.sensorID);
                }

                sensor = controller.GetSensor();
                List   = new List <Sensor>();

                foreach (var sensor1 in sensor.Result.Value.ToList())
                {
                    List.Add(sensor1);
                }


                Assert.AreEqual(Listcount - 1, List.Count);
            }
        }
Example #3
0
        public static void InitializeInsertSensor(JsonSensor jsonSensor)
        {
            Models.Sensor sensor = new Models.Sensor()
            {
                Luminosidade = jsonSensor.Luminosidade,
                Temperatura  = jsonSensor.Temperatura,
                Umidade      = jsonSensor.Umidade,
                Proximidade  = jsonSensor.Proximidade
            };

            InsertSensor(sensor);
        }
Example #4
0
        public ActionResult Delete(Models.Site site)
        {
            if (ModelState.IsValid)
            {
                //removed the site from the db
                Models.Site _site = database.sites.Find((int)site.SiteID);
                database.sites.Remove(_site);
                database.SaveChanges();

                //also remove equipment that has this assigned.
                IEnumerable <Models.FlowMeter> _flowmeters = database.flowMeters.Where(m => m.SiteId == site.SiteID);
                IEnumerable <Models.Sensor>    _sensors    = database.Sensors.Where(m => m.SiteID == site.SiteID);
                IEnumerable <Models.Telog>     _telogs     = database.telogs.Where(m => m.SiteID == site.SiteID);
                Models.Manhole manhole = database.manholes.Where(m => m.SiteID == site.SiteID).FirstOrDefault();

                foreach (var f in _flowmeters)
                {
                    Models.FlowMeter flowMeter = database.flowMeters.Find(f.ID);
                    database.flowMeters.Remove(flowMeter);
                }
                database.SaveChanges();

                foreach (var s in _sensors)
                {
                    Models.Sensor sensor = database.Sensors.Find(s.ID);
                    database.Sensors.Remove(sensor);
                }
                database.SaveChanges();

                foreach (var t in _telogs)
                {
                    Models.Telog telog = database.telogs.Find(t.TelogID);
                    database.telogs.Remove(telog);
                }
                database.SaveChanges();

                Models.Manhole mh = database.manholes.Find(manhole.ManholeID);
                database.manholes.Remove(mh);
                database.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View("Delete", site));
        }
Example #5
0
        private static void InsertSensor(Models.Sensor sensor)
        {
            SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["BI_LOCATIONCELL_Connection"].ConnectionString);

            string     procName = "InsertSensor";
            SqlCommand command  = new SqlCommand(procName, connection);

            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@paramLuminosidade", SqlDbType.NVarChar)).Value = sensor.Luminosidade;
            command.Parameters.Add(new SqlParameter("@paramTemperatura", SqlDbType.NVarChar)).Value  = sensor.Temperatura;
            command.Parameters.Add(new SqlParameter("@paramUmidade", SqlDbType.NVarChar)).Value      = sensor.Umidade;
            command.Parameters.Add(new SqlParameter("@paramProximidade", SqlDbType.NVarChar)).Value  = sensor.Proximidade;
            command.Parameters.Add(new SqlParameter("@paramDataCriacao", SqlDbType.DateTime)).Value  = DateTime.Now;

            //SqlParameter ParamId = cmd.Parameters.Add("@Id", SqlDbType.Int);
            //ParamId.Direction = ParameterDirection.InputOutput;
            //command.Parameter.Add(ParamId);

            connection.Open();
            command.ExecuteNonQuery();
            //int ID = ParamId.Value;
            connection.Close();
        }