Exemplo n.º 1
0
        public IEnumerable <DoorWindowSensorEntity> GetByDate(DateTime fromDate, DateTime toDate)
        {
            var command = this.SmartPlugConnection.Connection.CreateCommand();
            List <DoorWindowSensorEntity> list = new List <DoorWindowSensorEntity>();

            command.CommandText = selectByDateQueryString;
            command.CommandType = CommandType.Text;

            command.Parameters.AddWithValue("@fromDate", fromDate);
            command.Parameters.AddWithValue("@toDate", toDate);

            using (NpgsqlDataReader r = command.ExecuteReader())
            {
                while (r.Read())
                {
                    DoorWindowSensorEntity doorWindowSensorEntity = new DoorWindowSensorEntity
                    {
                        State     = Convert.ToString(r["state"]),
                        Light     = Convert.ToInt32(r["light"]),
                        CreatedAt = Convert.ToDateTime(r["created_at"])
                    };

                    list.Add(doorWindowSensorEntity);
                }
            }

            return(list);
        }
Exemplo n.º 2
0
        public void Insert(DoorWindowSensorEntity doorWindowSensorEntity)
        {
            var command = this.SmartPlugConnection.Connection.CreateCommand();

            command.CommandText = insertQueryString;
            command.CommandType = CommandType.Text;

            command.Parameters.AddWithValue("@state", doorWindowSensorEntity.State);
            command.Parameters.AddWithValue("@light", doorWindowSensorEntity.Light);
            command.Parameters.AddWithValue("@created_at", doorWindowSensorEntity.CreatedAt);

            command.ExecuteNonQuery();
        }