Thread on the server better

This commit is contained in:
2025-08-04 16:27:41 -07:00
parent 109306dda2
commit 35018d921b
4 changed files with 85 additions and 25 deletions
@@ -10,7 +10,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<Company?> GetCompany( int CompanyID ) {
Company? company = null;
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM Company
@@ -22,7 +22,6 @@ namespace BoredCareers.Services.DatabaseService {
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
while( await reader.ReadAsync() ) {
if( reader == null ) { break; }
int _id = reader.GetInt32("ID");
string _name = reader.GetString("Name");
string _email = reader.GetString("Email");
@@ -58,8 +57,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<int> SetCompany( Company company ) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
INSERT INTO Company
(ID,Name,Email,EmailVerified,WebsiteURL,Logo,Phone,PostalCode,Country,StateOrRegion,City,Description)
@@ -104,7 +102,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task DeleteCompany( int CompanyID ) {
using( MySqlConnection connection = GetConnection() ) {
MySqlCommand cmd;
connection.Open();
await connection.OpenAsync();
string command = @"
DELETE FROM Company WHERE ID = @ID;
@@ -10,7 +10,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<Employee?> GetEmployee( int EmployeeID ) {
Employee? employee = null;
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM Employee
@@ -23,7 +23,6 @@ namespace BoredCareers.Services.DatabaseService {
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
while( await reader.ReadAsync() ) {
if( reader == null ) { break; }
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
@@ -66,7 +65,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<Employee[]> GetEmployeesFromCompany(int CompanyID) {
List<Employee> employees = new List<Employee>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM Employee
@@ -79,7 +78,6 @@ namespace BoredCareers.Services.DatabaseService {
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
@@ -122,7 +120,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<Employee[]> GetEmployeesFromAccount(int AccountID) {
List<Employee> employees = new List<Employee>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM Employee
@@ -135,7 +133,6 @@ namespace BoredCareers.Services.DatabaseService {
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _accountid = reader.GetInt32("AccountID");
int _companyid = reader.GetInt32("CompanyID");
@@ -177,7 +174,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task SetEmployee(Employee employee) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
INSERT INTO Employee
@@ -201,7 +198,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task DeleteEmployee( int EmployeeID ) {
using( MySqlConnection connection = GetConnection() ) {
MySqlCommand cmd;
connection.Open();
await connection.OpenAsync();
string command = @"
DELETE FROM Employee WHERE ID = @ID;
@@ -9,7 +9,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<JobListing[]> GetJobListingPage(int PageNumber, int CountPerPage) {
List<JobListing> joblistings = new List<JobListing>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM JobListing
@@ -24,7 +24,6 @@ namespace BoredCareers.Services.DatabaseService {
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _companyid = reader.GetInt32("CompanyID");
string _title = reader.GetString("Title");
@@ -69,7 +68,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<JobListing[]> GetJobListingFromCompany(int CompanyID) {
List<JobListing> joblistings = new List<JobListing>(); ;
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM JobListing
@@ -81,7 +80,6 @@ namespace BoredCareers.Services.DatabaseService {
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _companyid = reader.GetInt32("CompanyID");
string _title = reader.GetString("Title");
@@ -126,7 +124,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<JobListing?> GetJobListing(int JobListingID) {
JobListing? joblisting = null;
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM JobListing
@@ -138,7 +136,6 @@ namespace BoredCareers.Services.DatabaseService {
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _companyid = reader.GetInt32("CompanyID");
string _title = reader.GetString("Title");
@@ -180,9 +177,78 @@ namespace BoredCareers.Services.DatabaseService {
return joblisting;
}
public async Task<JobListing[]> GetJobListingsPastExipre() {
List<JobListing> joblistings = new List<JobListing>();
using (MySqlConnection connection = GetConnection()) {
await connection.OpenAsync();
string command = @"
SELECT *
FROM JobListing
WHERE IsDeleted = FALSE
AND CreatedTime < NOW() - INTERVAL 1 MONTH;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
int _id = reader.GetInt32("ID");
int _companyid = reader.GetInt32("CompanyID");
string _title = reader.GetString("Title");
string _postalcode = reader.GetString("PostalCode");
string _country = reader.GetString("Country");
string _state = reader.GetString("StateOrRegion");
string _city = reader.GetString("City");
int _salarymin = reader.GetInt32("SalaryMin");
int _salarymax = reader.GetInt32("SalaryMax");
string _jobtype = reader.GetString("JobType");
bool _remote = reader.GetBoolean("Remote");
string _description = reader.GetString("Description");
JobListingSkill[] _skills = await GetJobListingSkills(_id);
DateTime _createtime = reader.GetDateTime("CreatedTime");
DateTime _modifiedtime = reader.GetDateTime("ModifiedTime");
bool _isdeleted = reader.GetBoolean("IsDeleted");
joblistings.Add(new JobListing() {
ID = _id,
CompanyID = _companyid,
Title = _title,
PostalCode = _postalcode,
Country = _country,
StateOrRegion = _state,
City = _city,
SalaryMin = _salarymin,
SalaryMax = _salarymax,
JobType = _jobtype,
Remote = _remote,
Description = _description,
Skills = _skills,
CreatedTime = _createtime,
ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted
});
}
}
}
return joblistings.ToArray();
}
public async Task DeleteJobListingsPastExipre() {
using (MySqlConnection connection = GetConnection()) {
await connection.OpenAsync();
string command = @"
UPDATE JobListing
SET IsDeleted = TRUE
WHERE IsDeleted = FALSE
AND CreatedTime < NOW() - INTERVAL 1 MONTH;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
await cmd.ExecuteNonQueryAsync();
}
}
public async Task SetJobListing(JobListing jobListing) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
INSERT INTO JobListing
@@ -234,7 +300,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task DeleteJobListing( int JobListingID ) {
using (MySqlConnection connection = GetConnection()) {
MySqlCommand cmd;
connection.Open();
await connection.OpenAsync();
string command = @"
UPDATE JobListing
@@ -9,7 +9,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task<JobListingSkill[]> GetJobListingSkills(int JobListingID) {
List<JobListingSkill> joblistingskills = new List<JobListingSkill>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
await connection.OpenAsync();
string command = @"
SELECT *
FROM JobListingSkill
@@ -41,8 +41,7 @@ namespace BoredCareers.Services.DatabaseService {
public async Task SetJobListingSkills( JobListingSkill jobListingSkill ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
await connection.OpenAsync();
string command = @"
INSERT INTO JobListing
(ID,JobListingID,Name,Description)