using System;
using System.Data.SqlClient;
class Program
{
static void Main()
{
// Connection string for your database
string connectionString = $"Data Source={orkout};Version=3;";
// Create a SqlConnection using the connection string
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Insert user
int userId;
using (SqlCommand insertUserCommand = new SqlCommand("INSERT INTO Users (UserName) VALUES (@User); SELECT SCOPE_IDENTITY();", connection))
{
insertUserCommand.Parameters.AddWithValue("@User", "Justyn Cushing");
// Execute the command and get the UserId
userId = Convert.ToInt32(insertUserCommand.ExecuteScalar());
}
// Insert workouts
using (SqlCommand insertWorkoutCommand = new SqlCommand("INSERT INTO Workouts (UserName, Day, Exercise, Weight) VALUES (@User, @Day, @Exercise, @Weight);", connection))
{
insertWorkoutCommand.Parameters.AddWithValue("@User", userId);
insertWorkoutCommand.Parameters.AddWithValue("@Day", "Monday");
insertWorkoutCommand.Parameters.AddWithValue("@Exercise", "Squats");
insertWorkoutCommand.Parameters.AddWithValue("@Weight", 50);
// Execute the command for each workout
insertWorkoutCommand.ExecuteNonQuery();
// Repeat for other workouts...
}
}
WeeklyWorkoutTracker weeklyTracker = new WeeklyWorkoutTracker();
// Create a user
User user = new User("Justyn Cushing");
// Add workouts for the user
weeklyTracker.AddWorkout(user, "Monday", "Squats", 50);
weeklyTracker.AddWorkout(user, "Wednesday", "Bench Press", 40);
weeklyTracker.AddWorkout(user, "Friday", "Deadlifts", 60);
// Display the weekly workouts for the user
weeklyTracker.DisplayWeeklyWorkouts();
}
}
public class WeeklyWorkoutTracker
{
private List<Workout> weeklyWorkouts;
public WeeklyWorkoutTracker()
{
weeklyWorkouts = new List<Workout>();
}
public void AddWorkout(User user, string day, string exercise, double weight)
{
Workout workout = new Workout
{
User = user,
Day = day,
Exercise = exercise,
Weight = weight
};
weeklyWorkouts.Add(workout);
}
public void DisplayWeeklyWorkouts()
{
foreach (var workout in weeklyWorkouts)
{
Console.WriteLine(workout);
}
}
}
public class Workout
{
public string? Day { get; set; }
public string? Exercise { get; set; }
public double Weight { get; set; }
public User? User { get; set; }
public override string ToString()
{
return $"On {Day}, {User?.UserName} performed {Exercise} with a weight of {Weight} lbs.\n";
}
}
public class User
{
public string UserName { get; set; }
public User(string userName)
{
UserName = userName;
}
}