Change employee to a left join

This commit is contained in:
2025-07-20 21:14:39 -07:00
parent a5573dce4e
commit fb7e37bfb0
6 changed files with 91 additions and 12 deletions
@@ -13,7 +13,8 @@ namespace BoredCareers.Services.DatabaseService {
string command = @"
SELECT *
FROM Employee
WHERE ID = @ID;
LEFT JOIN Company ON Employee.CompanyID = Company.ID
WHERE Employee.ID = @ID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
@@ -25,11 +26,35 @@ namespace BoredCareers.Services.DatabaseService {
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
string _name = reader.GetString("Name");
string _email = reader.GetString("Email");
bool _emailVerified = reader.GetBoolean("EmailVerified");
string _websiteurl = reader.GetString("WebsiteURL");
string _logourl = reader.GetString( "LogoURL" );
string _phone = reader.GetString( "Phone" );
string _postalcode = reader.GetString( "PostalCode" );
string _country = reader.GetString( "Country" );
string _state = reader.GetString( "StateOrRegion" );
string _city = reader.GetString( "City" );
string _description = reader.GetString( "Description" );
employee = new Employee() {
ID = _id,
AccountID = _accountid,
CompanyID = _companyid
Company = new Company {
ID = _companyid,
Name = _name,
Email = _email,
EmailVerified = _emailVerified,
WebsiteURL = _websiteurl,
LogoURL = _logourl,
Phone = _phone,
PostalCode = _postalcode,
Country = _country,
StateOrRegion = _state,
City = _city,
Description = _description
}
};
}
}
@@ -44,7 +69,8 @@ namespace BoredCareers.Services.DatabaseService {
string command = @"
SELECT *
FROM Employee
WHERE CompanyID = @CompanyID;
LEFT JOIN Company ON Employee.CompanyID = Company.ID
WHERE Employee.CompanyID = @ID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
@@ -56,11 +82,35 @@ namespace BoredCareers.Services.DatabaseService {
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
string _name = reader.GetString("Name");
string _email = reader.GetString("Email");
bool _emailVerified = reader.GetBoolean("EmailVerified");
string _websiteurl = reader.GetString("WebsiteURL");
string _logourl = reader.GetString( "LogoURL" );
string _phone = reader.GetString( "Phone" );
string _postalcode = reader.GetString( "PostalCode" );
string _country = reader.GetString( "Country" );
string _state = reader.GetString( "StateOrRegion" );
string _city = reader.GetString( "City" );
string _description = reader.GetString( "Description" );
employees.Add(new Employee() {
ID = _id,
AccountID = _accountid,
CompanyID = _companyid
Company = new Company {
ID = _companyid,
Name = _name,
Email = _email,
EmailVerified = _emailVerified,
WebsiteURL = _websiteurl,
LogoURL = _logourl,
Phone = _phone,
PostalCode = _postalcode,
Country = _country,
StateOrRegion = _state,
City = _city,
Description = _description
}
});
}
}
@@ -75,7 +125,8 @@ namespace BoredCareers.Services.DatabaseService {
string command = @"
SELECT *
FROM Employee
WHERE AccountID = @AccountID;
LEFT JOIN Company ON Employee.CompanyID = Company.ID
WHERE Employee.AccountID = @AccountID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
@@ -87,11 +138,35 @@ namespace BoredCareers.Services.DatabaseService {
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
string _name = reader.GetString("Name");
string _email = reader.GetString("Email");
bool _emailVerified = reader.GetBoolean("EmailVerified");
string _websiteurl = reader.GetString("WebsiteURL");
string _logourl = reader.GetString( "LogoURL" );
string _phone = reader.GetString( "Phone" );
string _postalcode = reader.GetString( "PostalCode" );
string _country = reader.GetString( "Country" );
string _state = reader.GetString( "StateOrRegion" );
string _city = reader.GetString( "City" );
string _description = reader.GetString( "Description" );
employees.Add(new Employee() {
ID = _id,
AccountID = _accountid,
CompanyID = _companyid
Company = new Company {
ID = _companyid,
Name = _name,
Email = _email,
EmailVerified = _emailVerified,
WebsiteURL = _websiteurl,
LogoURL = _logourl,
Phone = _phone,
PostalCode = _postalcode,
Country = _country,
StateOrRegion = _state,
City = _city,
Description = _description
}
});
}
}
@@ -116,7 +191,7 @@ namespace BoredCareers.Services.DatabaseService {
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", employee.ID);
cmd.Parameters.AddWithValue("@AccountID", employee.AccountID);
cmd.Parameters.AddWithValue("@CompanyID", employee.CompanyID);
cmd.Parameters.AddWithValue("@CompanyID", employee.Company.ID);
await cmd.ExecuteNonQueryAsync();
}