public bool PersistWeather(Datamodels.GalaxyDataModel galaxy) { bool result = false; try { IDbCommand command = this.getCommand(); command.CommandText = INSERT_GALAXY_SLQ; command.CommandType = CommandType.Text; command.Parameters.Add(new SqlParameter() { ParameterName = DAY_COLUMN, DbType = DbType.Int32, Value = galaxy.Day }); command.Parameters.Add(new SqlParameter() { ParameterName = WEATHER_COLUMN, DbType = DbType.String, Value = galaxy.Weather }); command.Parameters.Add(new SqlParameter() { ParameterName = PERIMETER_COLUMN, DbType = DbType.Int32, Value = galaxy.Perimeter }); command.Parameters.Add(new SqlParameter() { ParameterName = SUNIN_COLUMN, DbType = DbType.Int32, Value = galaxy.SunIn ? 1 : 0 }); command.ExecuteNonQuery(); result = true; } catch (Exception ex) { throw ex; } return(result); }
public Datamodels.GalaxyDataModel getModelByDay(int day) { Datamodels.GalaxyDataModel resultModel = null; try { IDbCommand command = this.getCommand(); command.CommandText = INSERT_GALAXY_SLQ; command.CommandType = CommandType.Text; command.Parameters.Add(new SqlParameter() { ParameterName = DAY_COLUMN, DbType = DbType.Int32, Value = day }); using (var dataReader = command.ExecuteReader()) { if (dataReader.Read()) { resultModel = new Datamodels.GalaxyDataModel(); resultModel.Id = Int32.Parse(dataReader[ID_COLUMN].ToString()); resultModel.Day = Int32.Parse(dataReader[DAY_COLUMN].ToString()); resultModel.Weather = dataReader[WEATHER_COLUMN].ToString(); resultModel.Perimeter = Double.Parse(dataReader[PERIMETER_COLUMN].ToString()); resultModel.SunIn = dataReader[SUNIN_COLUMN].ToString() == "1"; } dataReader.Close(); } } catch (Exception ex) { throw ex; } return(resultModel); }