public void SaveOrUpdate(Haircut haircut) { using var command = _connection.CreateCommand(); command.Connection = _connection; command.CommandText = $"update {Haircut.GetTableName()} " + $"set {Haircut.GetZodiacIdColumnName()} = :zodiacId, " + $"{Haircut.GetMoonDayColumnName()} = :moonDay, " + $"{Haircut.GetMoonPhaseColumnName()} = :moonPhase, " + $"{Haircut.GetPredictionColumnName()} = :prediction, " + $"{Haircut.GetIsPositiveColumnName()} = :isPositive " + $"where {Haircut.GetIdColumnName()} = :id;"; command.Parameters.AddWithValue("zodiacId", (int)haircut.Zodiac.Type); command.Parameters.AddWithValue("moonDay", haircut.MoonDay); command.Parameters.AddWithValue("moonPhase", haircut.MoonPhase); command.Parameters.AddWithValue("prediction", haircut.Prediction); command.Parameters.AddWithValue("isPositive", haircut.IsPositive); command.Parameters.AddWithValue("id", haircut.Id); Console.WriteLine("Execute SQL: " + command.CommandText); command.ExecuteNonQuery(); }
public List <Haircut> GetHaircuts() { using var command = _connection.CreateCommand(); command.Connection = _connection; command.CommandText = $"select {Haircut.GetIdColumnName()}, {Haircut.GetZodiacIdColumnName()}, {Haircut.GetMoonDayColumnName()}, " + $"{Haircut.GetMoonPhaseColumnName()}, {Haircut.GetPredictionColumnName()}, {Haircut.GetIsPositiveColumnName()} " + $"from {Haircut.GetTableName()};"; Console.WriteLine("Execute SQL: " + command.CommandText); return(Factory.CreateHaircutList(command.ExecuteReader(), this)); }