public void AddLog(Habit habit, DateTime currentDate) { Log currentLog = LogFactory.AddLog(habit, currentDate, new PostgresBadgeRepository(_connection, _transaction), new PostgresHabitRepository(_connection, _transaction)); string query = "INSERT INTO logs(id, habit_id, log,day,current_streak,longest_streak) VALUES(@id, @habit_id, @log,@day,@current_streak,@longest_streak)"; using (var cmd = new NpgsqlCommand(query, _connection, _transaction)) { cmd.Parameters.AddWithValue("id", Guid.NewGuid()); cmd.Parameters.AddWithValue("habit_id", habit.ID); cmd.Parameters.AddWithValue("log", currentLog.Logs[0]); cmd.Parameters.AddWithValue("day", currentLog.Days); cmd.Parameters.AddWithValue("current_streak", currentLog.current_streak); cmd.Parameters.AddWithValue("longest_streak", currentLog.longest_streak); cmd.ExecuteNonQuery(); } if (currentLog.longest_streak <= currentLog.current_streak) { createLogSnapshot(habit.ID); } }