working #18
@@ -167,3 +167,12 @@ CREATE TABLE IF NOT EXISTS `JobListing` (
|
||||
PRIMARY KEY (`ID`),
|
||||
FOREIGN KEY (`CompanyID`) REFERENCES `Company`(`ID`) ON DELETE CASCADE
|
||||
) AUTO_INCREMENT=1;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `JobListingSkill` (
|
||||
`ID` int NOT NULL AUTO_INCREMENT,
|
||||
`JobListingID` int NOT NULL,
|
||||
`Name` varchar(150) NOT NULL,
|
||||
`Description` text DEFAULT NULL,
|
||||
PRIMARY KEY (`ID`),
|
||||
FOREIGN KEY (`JobListingID`) REFERENCES `JobListing`(`ID`) ON DELETE CASCADE
|
||||
) AUTO_INCREMENT=1;
|
||||
@@ -11,7 +11,15 @@ export class JobListing {
|
||||
public jobType: string = "";
|
||||
public remote: boolean = false;
|
||||
public description: string = "";
|
||||
public skills: JobListingSkills[] = [];
|
||||
public createdTime: Date = new Date();
|
||||
public modifiedTime: Date = new Date();
|
||||
public isDeleted: boolean = false;
|
||||
}
|
||||
|
||||
export class JobListingSkills {
|
||||
public id: number | null = null;
|
||||
public jobListingID: number = 0;
|
||||
public name: string = "";
|
||||
public Description: string = "";
|
||||
}
|
||||
@@ -13,9 +13,17 @@ namespace BoredCareers.Entities {
|
||||
public string JobType { get; set; } = "";
|
||||
public bool Remote { get; set; } = false;
|
||||
public string Description { get; set; } = "";
|
||||
public JobListingSkill[] Skills { get; set; } = [];
|
||||
public DateTime CreatedTime { get; set; }
|
||||
public DateTime ModifiedTime { get; set; }
|
||||
public bool IsDeleted { get; set; } = false;
|
||||
}
|
||||
|
||||
public class JobListingSkill {
|
||||
public int? ID { get; set; } // PK
|
||||
public int JobListingID { get; set; } // FK
|
||||
public string Name { get; set; } = "";
|
||||
public string Description { get; set; } = "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -218,6 +224,10 @@ namespace BoredCareers.Services.DatabaseService {
|
||||
cmd.Parameters.AddWithValue("@IsDeleted", jobListing.IsDeleted);
|
||||
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
foreach (JobListingSkill cur in jobListing.Skills) {
|
||||
await SetJobListingSkills(cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user