Add Job Listing Skills

This commit is contained in:
2025-08-01 21:32:56 -07:00
parent 5480af64f6
commit 2c4292da07
5 changed files with 107 additions and 4 deletions
@@ -37,6 +37,7 @@ namespace BoredCareers.Services.DatabaseService {
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");
@@ -54,6 +55,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype,
Remote = _remote,
Description = _description,
Skills = _skills,
CreatedTime = _createtime,
ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted
@@ -92,6 +94,7 @@ namespace BoredCareers.Services.DatabaseService {
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");
@@ -109,6 +112,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype,
Remote = _remote,
Description = _description,
Skills = _skills,
CreatedTime = _createtime,
ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted
@@ -147,6 +151,7 @@ namespace BoredCareers.Services.DatabaseService {
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");
@@ -164,6 +169,7 @@ namespace BoredCareers.Services.DatabaseService {
JobType = _jobtype,
Remote = _remote,
Description = _description,
Skills = _skills,
CreatedTime = _createtime,
ModifiedTime = _modifiedtime,
IsDeleted = _isdeleted
@@ -175,7 +181,7 @@ namespace BoredCareers.Services.DatabaseService {
}
public async Task SetJobListing( JobListing jobListing ) {
using( MySqlConnection connection = GetConnection() ) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
@@ -200,7 +206,7 @@ namespace BoredCareers.Services.DatabaseService {
IsDeleted = @IsDeleted;
";
MySqlCommand cmd = new MySqlCommand( command , connection);
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", jobListing.ID);
cmd.Parameters.AddWithValue("@CompanyID", jobListing.CompanyID);
cmd.Parameters.AddWithValue("@Title", jobListing.Title);
@@ -218,11 +224,15 @@ namespace BoredCareers.Services.DatabaseService {
cmd.Parameters.AddWithValue("@IsDeleted", jobListing.IsDeleted);
await cmd.ExecuteNonQueryAsync();
foreach (JobListingSkill cur in jobListing.Skills) {
await SetJobListingSkills(cur);
}
}
}
public async Task DeleteJobListing( int JobListingID ) {
using( MySqlConnection connection = GetConnection() ) {
using (MySqlConnection connection = GetConnection()) {
MySqlCommand cmd;
connection.Open();
@@ -231,7 +241,7 @@ namespace BoredCareers.Services.DatabaseService {
SET IsDeleted = TRUE
WHERE ID = @ID;
";
cmd = new MySqlCommand( command, connection );
cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", JobListingID);
await cmd.ExecuteNonQueryAsync();
@@ -0,0 +1,68 @@
using BoredCareers.Entities;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.Common;
namespace BoredCareers.Services.DatabaseService {
public partial class DatabaseService {
public async Task<JobListingSkill[]> GetJobListingSkills(int JobListingID) {
List<JobListingSkill> joblistingskills = new List<JobListingSkill>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
SELECT *
FROM JobListingSkill
WHERE JobListingID = @JobListingID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@JobListingID", JobListingID);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) { break; }
int _id = reader.GetInt32("ID");
int _joblistingid = reader.GetInt32("JobListingID");
string _name = reader.GetString("Name");
string _description = reader.GetString("Description");
joblistingskills.Add(new JobListingSkill() {
ID = _id,
JobListingID = _joblistingid,
Name = _name,
Description = _description
});
}
}
}
return joblistingskills.ToArray();
}
public async Task SetJobListingSkills( JobListingSkill jobListingSkill ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
INSERT INTO JobListing
(ID,JobListingID,Name,Description)
VALUES
(@ID,@JobListingID,@Name,@Description)
ON DUPLICATE KEY UPDATE
JobListingID = @JobListingID,
Name = @Name,
Description = @Description;
";
MySqlCommand cmd = new MySqlCommand( command , connection);
cmd.Parameters.AddWithValue("@ID", jobListingSkill.ID);
cmd.Parameters.AddWithValue("@JobListingID", jobListingSkill.JobListingID);
cmd.Parameters.AddWithValue("@Name", jobListingSkill.Name);
cmd.Parameters.AddWithValue("@Description", jobListingSkill.Description);
await cmd.ExecuteNonQueryAsync();
}
}
}
}