public IEnumerable <HtSensorEntity> GetByDate(DateTime fromDate, DateTime toDate) { var command = this.SmartPlugConnection.Connection.CreateCommand(); List <HtSensorEntity> list = new List <HtSensorEntity>(); 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()) { HtSensorEntity htSensorEntity = new HtSensorEntity { Humidity = Convert.ToInt32(r["humidity"]), Temperature = Convert.ToDouble(r["temperature"]), CreatedAt = Convert.ToDateTime(r["created_at"]) }; list.Add(htSensorEntity); } } return(list); }
public void Insert(HtSensorEntity htSensorEntity) { var command = this.SmartPlugConnection.Connection.CreateCommand(); command.CommandText = insertQueryString; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@humidity", htSensorEntity.Humidity); command.Parameters.AddWithValue("@temperature", htSensorEntity.Temperature); command.Parameters.AddWithValue("@created_at", htSensorEntity.CreatedAt); command.ExecuteNonQuery(); }