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

            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())
                {
                    EmeterEntity emeterEntity = new EmeterEntity
                    {
                        Voltage   = Convert.ToInt32(r["voltage"]),
                        Current   = Convert.ToInt32(r["current"]),
                        Power     = Convert.ToInt32(r["power"]),
                        CreatedAt = Convert.ToDateTime(r["created_at"])
                    };

                    emeterEntities.Add(emeterEntity);
                }
            }

            return(emeterEntities);
        }
Ejemplo n.º 2
0
        public void Insert(EmeterEntity emeter)
        {
            var command = this.SmartPlugConnection.Connection.CreateCommand();

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

            command.Parameters.AddWithValue("@current", emeter.Current);
            command.Parameters.AddWithValue("@voltage", emeter.Voltage);
            command.Parameters.AddWithValue("@power", emeter.Power);
            command.Parameters.AddWithValue("@created_at", emeter.CreatedAt);

            command.ExecuteNonQuery();
        }