public HabitResponse(Habit.Habit habit) { this.ID = habit.ID; this.Name = habit.Name.Value; this.DaysOff = habit.DaysOff.Value; this.CurrentStreak = habit.Log.CurrentStreak; this.LongestStreak = habit.Log.LongestStreak; this.LogCount = habit.Log.LogCount; this.Logs = habit.Log.Logs; this.UserID = habit.UserID; this.CreatedAt = habit.CreatedAt; }
public void Create(Habit.Habit habit) { string query = "INSERT INTO habits (id, name, day_off, user_id, created_at) VALUES (@id, @name, @day_off, @user_id, @created_at)"; using var cmd = new NpgsqlCommand(query, _connection, _transaction); cmd.Parameters.AddWithValue("id", Guid.NewGuid()); cmd.Parameters.AddWithValue("name", habit.Name.Value); cmd.Parameters.AddWithValue("day_off", habit.DaysOff.Value); cmd.Parameters.AddWithValue("user_id", habit.UserID); cmd.Parameters.AddWithValue("created_at", habit.CreatedAt); cmd.ExecuteNonQuery(); }