From 369d71d44699a0f1a1dd73ec131420079e1dfe3b Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Wed, 13 Aug 2025 06:28:14 -0700 Subject: [PATCH 1/7] Remove Veteran, Allow Millitary to be NULL --- database/mistox.sql | 1 - src/Client/src/app/models/Resume.ts | 3 +-- .../resumes/editor/editor.component.html | 4 +-- .../pages/resumes/editor/editor.component.ts | 27 ++++++++++++++----- src/Server/Entities/Resume.cs | 3 +-- .../ResumeParts/GetResumeParts.cs | 2 -- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/database/mistox.sql b/database/mistox.sql index 035a927..41a6cd6 100755 --- a/database/mistox.sql +++ b/database/mistox.sql @@ -48,7 +48,6 @@ CREATE TABLE IF NOT EXISTS `Resume` ( CREATE TABLE IF NOT EXISTS `ResumeMilitary` ( `ID` int NOT NULL AUTO_INCREMENT, `ResumeID` int NOT NULL, - `Veteran` boolean DEFAULT 0, `Country` char(2) NOT NULL, `Rank` varchar(50) NOT NULL, `DateStarted` date NOT NULL, diff --git a/src/Client/src/app/models/Resume.ts b/src/Client/src/app/models/Resume.ts index 92826d8..9efabed 100644 --- a/src/Client/src/app/models/Resume.ts +++ b/src/Client/src/app/models/Resume.ts @@ -14,7 +14,7 @@ export class Resume { public city: string = ""; public isActive: boolean = false; public experience: ResumeExperience[] = []; - public military: ResumeMilitary = new ResumeMilitary; + public military: ResumeMilitary | null = new ResumeMilitary; public education: ResumeEducation[] = []; public skills: ResumeSkill[] = []; public languages: ResumeLanguage[] = []; @@ -53,7 +53,6 @@ export class ResumeMilitary { public id: number | null = null; public resumeID: number | null = null; - public veteran: boolean = false; public country: string = ""; public rank: string = ""; public dateStarted: Date = new Date(); diff --git a/src/Client/src/app/pages/resumes/editor/editor.component.html b/src/Client/src/app/pages/resumes/editor/editor.component.html index 9cc4cc0..179d15c 100644 --- a/src/Client/src/app/pages/resumes/editor/editor.component.html +++ b/src/Client/src/app/pages/resumes/editor/editor.component.html @@ -43,8 +43,8 @@
-

Is Veteran:

- @if(resume.military.veteran){ +

Is Veteran:

+ @if(resume.military !== null){ diff --git a/src/Client/src/app/pages/resumes/editor/editor.component.ts b/src/Client/src/app/pages/resumes/editor/editor.component.ts index bbbbd10..f7aa2f0 100644 --- a/src/Client/src/app/pages/resumes/editor/editor.component.ts +++ b/src/Client/src/app/pages/resumes/editor/editor.component.ts @@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms'; import { Router, ActivatedRoute, RouterModule } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { CommonModule } from '@angular/common'; -import { Resume, ResumeCertification, ResumeEducation, ResumeExperience, ResumeExperienceBullet, ResumeLanguage, ResumeMilitaryBullet, ResumeProject, ResumeSkill } from 'app/models/Resume'; +import { Resume, ResumeCertification, ResumeEducation, ResumeExperience, ResumeExperienceBullet, ResumeLanguage, ResumeMilitary, ResumeMilitaryBullet, ResumeProject, ResumeSkill } from 'app/models/Resume'; import { Authentication } from 'app/services/Authentication'; import { HomeComponent } from "app/pages/home/home.component"; @@ -33,6 +33,7 @@ export class ResumesEditorComponent { this.http.get("api/resume?ResumeID=" + ResumeID).subscribe({ next: data => { this.resume = data; + this.milCache = data.military; this.isNewResume = false; }, error: err => { @@ -81,15 +82,27 @@ export class ResumesEditorComponent { } } + milCache: ResumeMilitary | null = new ResumeMilitary; + onVeteranChange(event: Event){ + const checkbox = event.target as HTMLInputElement; + const isChecked = checkbox.checked; + if (isChecked){ + this.resume.military = this.milCache; + } else { + this.resume.military = null; + } + } addMillitaryBullet(){ - this.resume.military.millitaryBullets.push( new ResumeMilitaryBullet ); + this.resume.military?.millitaryBullets.push( new ResumeMilitaryBullet ); } delMillitaryBullet(self: ResumeMilitaryBullet){ - for(let i=0; i Date: Wed, 13 Aug 2025 06:28:59 -0700 Subject: [PATCH 2/7] Start work on fixing DbDriver --- ToDo.yaml | 1 + src/Server/Services/DatabaseService/Resume.cs | 205 ++++++------------ .../ResumeParts/SetResumeParts.cs | 82 ++++--- 3 files changed, 124 insertions(+), 164 deletions(-) diff --git a/ToDo.yaml b/ToDo.yaml index 855e616..f162401 100755 --- a/ToDo.yaml +++ b/ToDo.yaml @@ -50,6 +50,7 @@ Client: resume/editor: Not fully tested yet + Veteran needs to be moved from the Resume/millitary into the Resume so it doesnt have to save the whole millitary object to the db if not needed Company: Need to impliment Add employee diff --git a/src/Server/Services/DatabaseService/Resume.cs b/src/Server/Services/DatabaseService/Resume.cs index 35cf14e..916704e 100644 --- a/src/Server/Services/DatabaseService/Resume.cs +++ b/src/Server/Services/DatabaseService/Resume.cs @@ -58,101 +58,47 @@ namespace BoredCareers.Services.DatabaseService { return resumes.ToArray(); } + private async Task ExecuteReaderAsync(MySqlConnection conn, string query, int resumeId) { + var cmd = new MySqlCommand(query, conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + return await cmd.ExecuteReaderAsync(); + } + public async Task GetResume(int ResumeID) { - // Open connections for multi-threaded request - MySqlConnection resumeConnection = GetConnection(); - MySqlConnection ResumeExperienceConnection = GetConnection(); - MySqlConnection ResumeExperienceBulletConnection = GetConnection(); - MySqlConnection ResumeMilitaryConnection = GetConnection(); - MySqlConnection ResumeMilitaryBulletConnection = GetConnection(); - MySqlConnection ResumeEducationConnection = GetConnection(); - MySqlConnection ResumeSkillConnection = GetConnection(); - MySqlConnection ResumeLanguageConnection = GetConnection(); - MySqlConnection ResumeCertificationConnection = GetConnection(); - MySqlConnection ResumeProjectConnection = GetConnection(); + using (var conn = GetConnection()) { + await conn.OpenAsync(); - // Open the connections - Task resumeopen = resumeConnection.OpenAsync(); - Task resumeexperienceopen = ResumeExperienceConnection.OpenAsync(); - Task resumeexperiencebulletopen = ResumeExperienceBulletConnection.OpenAsync(); - Task resumemilitaryopen = ResumeMilitaryConnection.OpenAsync(); - Task resumemilitarybulletopen = ResumeMilitaryBulletConnection.OpenAsync(); - Task resumeeducationopen = ResumeEducationConnection.OpenAsync(); - Task resumeskillopen = ResumeSkillConnection.OpenAsync(); - Task resumelanguageopen = ResumeLanguageConnection.OpenAsync(); - Task resumecertifcationopen = ResumeCertificationConnection.OpenAsync(); - Task resumeprojectopen = ResumeProjectConnection.OpenAsync(); + Resume? resume = await GetResume(await ExecuteReaderAsync(conn, "SELECT * FROM Resume WHERE ID = @ResumeID;", ResumeID)); + if (resume == null) { return null; } - // Wait for all the connections to open - await Task.WhenAll(resumeopen, resumeexperienceopen, resumeexperiencebulletopen, resumemilitaryopen, resumemilitarybulletopen, - resumeeducationopen, resumeskillopen, resumelanguageopen, resumecertifcationopen, resumeprojectopen); + Task[] tasks = [ + ExecuteReaderAsync(conn, "SELECT * FROM ResumeExperience WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeExperienceBullet WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeMilitary WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeMilitaryBullet WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeEducation WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeSkill WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeLanguage WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeCertification WHERE ResumeID = @ResumeID;", ResumeID), + ExecuteReaderAsync(conn, "SELECT * FROM ResumeProject WHERE ResumeID = @ResumeID;", ResumeID), + ]; + await Task.WhenAll(tasks); - // Setup the commands for the connections - MySqlCommand resumeCommand = new MySqlCommand("SELECT * FROM Resume WHERE ID = @ResumeID;", resumeConnection); - MySqlCommand ResumeExperienceCommand = new MySqlCommand("SELECT * FROM ResumeExperience WHERE ResumeID = @ResumeID;", ResumeExperienceConnection); - MySqlCommand ResumeExperienceBulletCommand = new MySqlCommand("SELECT * FROM ResumeExperienceBullet WHERE ResumeID = @ResumeID;", ResumeExperienceBulletConnection); - MySqlCommand ResumeMilitaryCommand = new MySqlCommand("SELECT * FROM ResumeMilitary WHERE ResumeID = @ResumeID;", ResumeMilitaryConnection); - MySqlCommand ResumeMilitaryBulletCommand = new MySqlCommand("SELECT * FROM ResumeMilitaryBullet WHERE ResumeID = @ResumeID", ResumeMilitaryBulletConnection); - MySqlCommand ResumeEducationCommand = new MySqlCommand("SELECT * FROM ResumeEducation WHERE ResumeID = @ResumeID;", ResumeEducationConnection); - MySqlCommand ResumeSkillCommand = new MySqlCommand("SELECT * FROM ResumeSkill WHERE ResumeID = @ResumeID;", ResumeSkillConnection); - MySqlCommand ResumeLanguageCommand = new MySqlCommand("SELECT * FROM ResumeLanguage WHERE ResumeID = @ResumeID;", ResumeLanguageConnection); - MySqlCommand ResumeCertificationCommand = new MySqlCommand("SELECT * FROM ResumeCertification WHERE ResumeID = @ResumeID;", ResumeCertificationConnection); - MySqlCommand ResumeProjectCommand = new MySqlCommand("SELECT * FROM ResumeProject WHERE ResumeID = @ResumeID;", ResumeProjectConnection); + ResumeExperience[] experience = await GetResumeExperience(await tasks[0]); + ResumeExperienceBullet[] bullets = await GetResumeExperienceBullets(await tasks[1]); + ResumeMilitary? military = await GetResumeMilitary(await tasks[2]); + ResumeMilitaryBullet[] militaryBullets = await GetResumeMilitaryBullets(await tasks[3]); + ResumeEducation[] education = await GetResumeEducation(await tasks[4]); + ResumeSkill[] skills = await GetResumeSkills(await tasks[5]); + ResumeLanguage[] languages = await GetResumeLanguages(await tasks[6]); + ResumeCertification[] certs = await GetResumeCertification(await tasks[7]); + ResumeProject[] projects = await GetResumeProjects(await tasks[8]); - // Add parameters to the commands - resumeCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeExperienceCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeExperienceBulletCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeMilitaryCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeMilitaryBulletCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeEducationCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeSkillCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeLanguageCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeCertificationCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - ResumeProjectCommand.Parameters.AddWithValue("@ResumeID", ResumeID); - - // Run the commands - Task ResumeReader = resumeCommand.ExecuteReaderAsync(); - Task ResumeExperienceReader = ResumeExperienceCommand.ExecuteReaderAsync(); - Task ResumeExperienceBulletReader = ResumeExperienceBulletCommand.ExecuteReaderAsync(); - Task ResumeMilitaryReader = ResumeMilitaryCommand.ExecuteReaderAsync(); - Task ResumeMilitaryBulletReader = ResumeMilitaryBulletCommand.ExecuteReaderAsync(); - Task ResumeEducationReader = ResumeEducationCommand.ExecuteReaderAsync(); - Task ResumeSkillReader = ResumeSkillCommand.ExecuteReaderAsync(); - Task ResumeLanguageReader = ResumeLanguageCommand.ExecuteReaderAsync(); - Task ResumeCertificationReader = ResumeCertificationCommand.ExecuteReaderAsync(); - Task ResumeProjectReader = ResumeProjectCommand.ExecuteReaderAsync(); - - // Wait for all the commands to process - await Task.WhenAll(ResumeReader, ResumeExperienceReader, ResumeExperienceBulletReader, ResumeMilitaryReader, ResumeMilitaryBulletReader, - ResumeEducationReader, ResumeSkillReader, ResumeLanguageReader, ResumeCertificationReader, ResumeProjectReader); - - // Get Resume - Resume? resume = await GetResume( await ResumeReader ); - if (resume != null) { - - // Get Resume Parts - ResumeExperience[] experience = await GetResumeExperience(await ResumeExperienceReader); - ResumeExperienceBullet[] experienceBullets = await GetResumeExperienceBullets(await ResumeExperienceBulletReader); - ResumeMilitary? military = await GetResumeMilitary(await ResumeMilitaryReader); - ResumeMilitaryBullet[] militaryBullets = await GetResumeMilitaryBullets(await ResumeMilitaryBulletReader); - ResumeEducation[] education = await GetResumeEducation(await ResumeEducationReader); - ResumeSkill[] skills = await GetResumeSkills(await ResumeSkillReader); - ResumeLanguage[] languages = await GetResumeLanguages(await ResumeLanguageReader); - ResumeCertification[] certs = await GetResumeCertification(await ResumeCertificationReader); - ResumeProject[] projects = await GetResumeProjects(await ResumeProjectReader); - - // Split into grouped lists and add to experience - Dictionary groupedExperienceBullets = experienceBullets.GroupBy(b => b.ResumeExperienceID).ToDictionary(g => g.Key, g => g.ToArray()); - foreach (ResumeExperience cur in experience) { - cur.ExperienceBullets = groupedExperienceBullets[Convert.ToInt32(cur.ID)]; + Dictionary groupedExperienceBullets = bullets.GroupBy(b => b.ResumeExperienceID).ToDictionary(g => g.Key, g => g.ToArray()); + foreach (var exp in experience) { + exp.ExperienceBullets = groupedExperienceBullets.TryGetValue(Convert.ToInt32(exp.ID), out var b) ? b : Array.Empty(); } - // Add the parts to the resume - if (military != null) { - military.MillitaryBullets = militaryBullets; - resume.Millitary = military; - } resume.Experience = experience; resume.Educations = education; resume.Skills = skills; @@ -160,63 +106,52 @@ namespace BoredCareers.Services.DatabaseService { resume.Certification = certs; resume.Projects = projects; + if (military != null) { + military.MillitaryBullets = militaryBullets; + resume.Millitary = military; + } + return resume; } - return null; } public async Task SetResume(Resume resume) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); - // Open connections for multi-threaded request - MySqlConnection resumeConnection = GetConnection(); - MySqlConnection ResumeExperienceConnection = GetConnection(); - MySqlConnection ResumeExperienceBulletConnection = GetConnection(); - MySqlConnection ResumeMilitaryConnection = GetConnection(); - MySqlConnection ResumeMilitaryBulletConnection = GetConnection(); - MySqlConnection ResumeEducationConnection = GetConnection(); - MySqlConnection ResumeSkillConnection = GetConnection(); - MySqlConnection ResumeLanguageConnection = GetConnection(); - MySqlConnection ResumeCertificationConnection = GetConnection(); - MySqlConnection ResumeProjectConnection = GetConnection(); + // Set ResumeID on layer 1 nodes + int _ResumeID = await SetResume(conn, resume); + if (resume.Millitary != null) { resume.Millitary.ResumeID = _ResumeID; } + foreach (ResumeExperience cur in resume.Experience) { cur.ResumeID = _ResumeID; } + foreach (ResumeEducation cur in resume.Educations) { cur.ResumeID = _ResumeID; } + foreach (ResumeSkill cur in resume.Skills) { cur.ResumeID = _ResumeID; } + foreach (ResumeLanguage cur in resume.Languages) { cur.ResumeID = _ResumeID; } + foreach (ResumeCertification cur in resume.Certification) { cur.ResumeID = _ResumeID; } + foreach (ResumeProject cur in resume.Projects) { cur.ResumeID = _ResumeID; } - // Open the connections - Task resumeopen = resumeConnection.OpenAsync(); - Task resumeexperienceopen = ResumeExperienceConnection.OpenAsync(); - Task resumeexperiencebulletopen = ResumeExperienceBulletConnection.OpenAsync(); - Task resumemilitaryopen = ResumeMilitaryConnection.OpenAsync(); - Task resumemilitarybulletopen = ResumeMilitaryBulletConnection.OpenAsync(); - Task resumeeducationopen = ResumeEducationConnection.OpenAsync(); - Task resumeskillopen = ResumeSkillConnection.OpenAsync(); - Task resumelanguageopen = ResumeLanguageConnection.OpenAsync(); - Task resumecertifcationopen = ResumeCertificationConnection.OpenAsync(); - Task resumeprojectopen = ResumeProjectConnection.OpenAsync(); + Task[] tasks = [ + SetResumeExperience(conn, resume.Experience), + SetResumeMilitary(conn, resume.Millitary), + SetResumeEducation(conn, resume.Educations), + SetResumeSkills(conn, resume.Skills), + SetResumeLanguages(conn, resume.Languages), + SetResumeCertification(conn, resume.Certification), + SetResumeProjects(conn, resume.Projects) + ]; + await Task.WhenAll(tasks); - // Wait for all the connections to open - await Task.WhenAll(resumeopen, resumeexperienceopen, resumeexperiencebulletopen, resumemilitaryopen, resumemilitarybulletopen, - resumeeducationopen, resumeskillopen, resumelanguageopen, resumecertifcationopen, resumeprojectopen); - - // Get all the experience bullets and run all the updates - List bullets = new List(); - foreach (ResumeExperience cur in resume.Experience) { - foreach (ResumeExperienceBullet bullet in cur.ExperienceBullets) { - bullets.Add(bullet); + List bullets = new List(); + foreach (ResumeExperience cur in resume.Experience) { + foreach (ResumeExperienceBullet bullet in cur.ExperienceBullets) { + bullets.Add(bullet); + } } + + Task ResumeExperienceBulletTask = SetResumeExperienceBullets(ResumeExperienceBulletConnection, bullets.ToArray()); + Task ResumeMilitaryBulletTask = SetResumeMilitaryBullets(ResumeMilitaryBulletConnection, resume.Millitary.MillitaryBullets); + + return resume; } - Task ResumeExperienceBulletTask = SetResumeExperienceBullets(ResumeExperienceBulletConnection, bullets.ToArray()); - Task ResumeTask = SetResume(resumeConnection, resume); - Task ResumeExperienceTask = SetResumeExperience(ResumeExperienceConnection, resume.Experience); - Task ResumeMilitaryTask = SetResumeMilitary(ResumeMilitaryConnection, resume.Millitary); - Task ResumeMilitaryBulletTask = SetResumeMilitaryBullets(ResumeMilitaryBulletConnection, resume.Millitary.MillitaryBullets); - Task ResumeEducationTask = SetResumeEducation(ResumeEducationConnection, resume.Educations); - Task ResumeSkllTask = SetResumeSkills(ResumeSkillConnection, resume.Skills); - Task ResumeLanguageTask = SetResumeLanguages(ResumeLanguageConnection, resume.Languages); - Task ResumeCertTask = SetResumeCertification(ResumeCertificationConnection, resume.Certification); - Task ResumeProjectTask = SetResumeProjects(ResumeProjectConnection, resume.Projects); - - // Allow update to finish before closing process - await Task.WhenAll(ResumeTask, ResumeExperienceTask, ResumeExperienceBulletTask, ResumeMilitaryTask, ResumeMilitaryBulletTask, - ResumeEducationTask, ResumeSkllTask, ResumeLanguageTask, ResumeCertTask, ResumeProjectTask); - } public async Task DeleteResume( int ResumeID ) { diff --git a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs index 85c993d..ddef872 100644 --- a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs +++ b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs @@ -4,7 +4,7 @@ using MySql.Data.MySqlClient; namespace BoredCareers.Services.DatabaseService { public partial class DatabaseService { - public async Task SetResume(MySqlConnection connection, Resume resume) { + public async Task SetResume(MySqlConnection connection, Resume resume) { string command = @" INSERT INTO Resume (ID,AccountID,Title,Name,Field,Email,PhoneNumber,PostalCode,Country,StateOrRegion,City,IsActive) @@ -22,6 +22,8 @@ namespace BoredCareers.Services.DatabaseService { StateOrRegion = @StateOrRegion, City = @City, IsActive = @IsActive; + + SELECT LAST_INSERT_ID(); "; MySqlCommand cmd = new MySqlCommand(command, connection); @@ -37,8 +39,14 @@ namespace BoredCareers.Services.DatabaseService { cmd.Parameters.AddWithValue("@StateOrRegion", resume.StateOrRegion); cmd.Parameters.AddWithValue("@City", resume.City); cmd.Parameters.AddWithValue("@IsActive", resume.IsActive); + object? result = await cmd.ExecuteScalarAsync(); - await cmd.ExecuteNonQueryAsync(); + if (resume.ID != null && resume.ID != 0) { + return Convert.ToInt32(resume.ID); + } else { + cmd.CommandText = ""; + return Convert.ToInt32(result); + } } public async Task SetResumeExperienceBullets(MySqlConnection connection, ResumeExperienceBullet[] bullets) { @@ -64,7 +72,7 @@ namespace BoredCareers.Services.DatabaseService { } } - public async Task SetResumeExperience(MySqlConnection connection, ResumeExperience[] experiences) { + public async Task SetResumeExperience(MySqlConnection connection, ResumeExperience[] experiences) { foreach (ResumeExperience cur in experiences) { string command = @" INSERT INTO Resume @@ -82,6 +90,8 @@ namespace BoredCareers.Services.DatabaseService { DateStarted = @DateStarted, StillEmployed = @StillEmployed, DateEnded = @DateEnded; + + SELECT LAST_INSERT_ID(); "; MySqlCommand cmd = new MySqlCommand(command, connection); @@ -93,8 +103,14 @@ namespace BoredCareers.Services.DatabaseService { cmd.Parameters.AddWithValue("@DateStarted", cur.DateStarted.ToUniversalTime()); cmd.Parameters.AddWithValue("@StillEmployed", cur.StillEmployed); cmd.Parameters.AddWithValue("@DateEnded", cur.DateEnded.ToUniversalTime()); + object? result = await cmd.ExecuteScalarAsync(); - await cmd.ExecuteNonQueryAsync(); + if (cur.ID != null && cur.ID != 0) { + return Convert.ToInt32(cur.ID); + } else { + cmd.CommandText = ""; + return Convert.ToInt32(result); + } } } @@ -123,33 +139,41 @@ namespace BoredCareers.Services.DatabaseService { } } - public async Task SetResumeMilitary(MySqlConnection connection, ResumeMilitary military) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,Veteran,Country,Rank,DateStarted,StillServing,DateEnded) - VALUES - (@ID,@ResumeID,@Veteran,@Country,@Rank,@DateStarted,@StillServing,@DateEnded) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - Veteran = @Veteran, - Country = @Country, - Rank = @Rank, - DateStarted = @DateStarted, - StillServing = @StillServing, - DateEnded = @DateEnded; - "; + public async Task SetResumeMilitary(MySqlConnection connection, ResumeMilitary? military) { + if (military != null) { + string command = @" + INSERT INTO Resume + (ID,ResumeID,Country,Rank,DateStarted,StillServing,DateEnded) + VALUES + (@ID,@ResumeID,@Country,@Rank,@DateStarted,@StillServing,@DateEnded) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Country = @Country, + Rank = @Rank, + DateStarted = @DateStarted, + StillServing = @StillServing, + DateEnded = @DateEnded; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", military.ID); - cmd.Parameters.AddWithValue("@ResumeID", military.ResumeID); - cmd.Parameters.AddWithValue("@Veteran", military.Veteran); - cmd.Parameters.AddWithValue("@Country", military.Country); - cmd.Parameters.AddWithValue("@Rank", military.Rank); - cmd.Parameters.AddWithValue("@DateStarted", military.DateStarted.ToUniversalTime()); - cmd.Parameters.AddWithValue("@StillServing", military.StillServing); - cmd.Parameters.AddWithValue("@DateEnded", military.DateEnded.ToUniversalTime()); + SELECT LAST_INSERT_ID(); + "; - await cmd.ExecuteNonQueryAsync(); + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@ID", military.ID); + cmd.Parameters.AddWithValue("@ResumeID", military.ResumeID); + cmd.Parameters.AddWithValue("@Country", military.Country); + cmd.Parameters.AddWithValue("@Rank", military.Rank); + cmd.Parameters.AddWithValue("@DateStarted", military.DateStarted.ToUniversalTime()); + cmd.Parameters.AddWithValue("@StillServing", military.StillServing); + cmd.Parameters.AddWithValue("@DateEnded", military.DateEnded.ToUniversalTime()); + object? result = await cmd.ExecuteScalarAsync(); + + if (military.ID != null && military.ID != 0) { + return Convert.ToInt32(military.ID); + } else { + cmd.CommandText = ""; + return Convert.ToInt32(result); + } + } } public async Task SetResumeEducation(MySqlConnection connection, ResumeEducation[] educations) { -- 2.52.0 From 88847f0ddcecf09bd347d5d5fb06ec7d667695bd Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Wed, 13 Aug 2025 13:10:40 -0700 Subject: [PATCH 3/7] Finalize the DbDriver --- src/Server/Services/DatabaseService/Resume.cs | 48 ++++++-- .../ResumeParts/SetResumeParts.cs | 115 ++++++++---------- 2 files changed, 90 insertions(+), 73 deletions(-) diff --git a/src/Server/Services/DatabaseService/Resume.cs b/src/Server/Services/DatabaseService/Resume.cs index 916704e..3daa744 100644 --- a/src/Server/Services/DatabaseService/Resume.cs +++ b/src/Server/Services/DatabaseService/Resume.cs @@ -119,19 +119,28 @@ namespace BoredCareers.Services.DatabaseService { using (var conn = GetConnection()) { await conn.OpenAsync(); - // Set ResumeID on layer 1 nodes + // Set ResumeID on all nodes int _ResumeID = await SetResume(conn, resume); - if (resume.Millitary != null) { resume.Millitary.ResumeID = _ResumeID; } - foreach (ResumeExperience cur in resume.Experience) { cur.ResumeID = _ResumeID; } + if (resume.Millitary != null) { + resume.Millitary.ResumeID = _ResumeID; + foreach (ResumeMilitaryBullet cur in resume.Millitary.MillitaryBullets) { + cur.ResumeID = _ResumeID; + } + } foreach (ResumeEducation cur in resume.Educations) { cur.ResumeID = _ResumeID; } foreach (ResumeSkill cur in resume.Skills) { cur.ResumeID = _ResumeID; } foreach (ResumeLanguage cur in resume.Languages) { cur.ResumeID = _ResumeID; } foreach (ResumeCertification cur in resume.Certification) { cur.ResumeID = _ResumeID; } foreach (ResumeProject cur in resume.Projects) { cur.ResumeID = _ResumeID; } + foreach (ResumeExperience cur in resume.Experience) { + cur.ResumeID = _ResumeID; + foreach (ResumeExperienceBullet us in cur.ExperienceBullets) { + us.ResumeID = _ResumeID; + } + } + // Async process all non child node SQL sets Task[] tasks = [ - SetResumeExperience(conn, resume.Experience), - SetResumeMilitary(conn, resume.Millitary), SetResumeEducation(conn, resume.Educations), SetResumeSkills(conn, resume.Skills), SetResumeLanguages(conn, resume.Languages), @@ -140,17 +149,32 @@ namespace BoredCareers.Services.DatabaseService { ]; await Task.WhenAll(tasks); - List bullets = new List(); - foreach (ResumeExperience cur in resume.Experience) { - foreach (ResumeExperienceBullet bullet in cur.ExperienceBullets) { - bullets.Add(bullet); + // Setup military task + if (resume.Millitary != null) { + ResumeMilitary militaryTask = await SetResumeMilitary(conn, resume.Millitary); + foreach (ResumeMilitaryBullet cur in resume.Millitary.MillitaryBullets) { + cur.ResumeMilitaryID = Convert.ToInt32(militaryTask.ID); } + await SetResumeMilitaryBullets(conn, resume.Millitary.MillitaryBullets); } - Task ResumeExperienceBulletTask = SetResumeExperienceBullets(ResumeExperienceBulletConnection, bullets.ToArray()); - Task ResumeMilitaryBulletTask = SetResumeMilitaryBullets(ResumeMilitaryBulletConnection, resume.Millitary.MillitaryBullets); + // Setup async process all experience tasks + List> experienceTasks = new List>(); + foreach (ResumeExperience cur in resume.Experience) { + experienceTasks.Add(SetResumeExperience(conn, cur)); + } + await Task.WhenAll(experienceTasks); - return resume; + // Assuming they are returned in the same order they are sent + List experienceBulletTasks = new List(); + for (int i = 0; i < experienceTasks.Count; i++) { + ResumeExperience self = await experienceTasks[i]; + foreach (ResumeExperienceBullet cur in resume.Experience[i].ExperienceBullets) { + cur.ResumeExperienceID = Convert.ToInt32(self.ID); + experienceBulletTasks.Add(SetResumeExperienceBullets(conn, cur)); + } + } + await Task.WhenAll(experienceBulletTasks); } } diff --git a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs index ddef872..47054ab 100644 --- a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs +++ b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs @@ -49,69 +49,63 @@ namespace BoredCareers.Services.DatabaseService { } } - public async Task SetResumeExperienceBullets(MySqlConnection connection, ResumeExperienceBullet[] bullets) { - foreach (ResumeExperienceBullet cur in bullets) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,ResumeExperienceID,JobFunction) - VALUES - (@ID,@ResumeID,@ResumeExperienceID,@JobFunction) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - ResumeExperienceID = @ResumeExperienceID, - JobFunction = @JobFunction; - "; + public async Task SetResumeExperienceBullets(MySqlConnection connection, ResumeExperienceBullet bullet) { + string command = @" + INSERT INTO Resume + (ID,ResumeID,ResumeExperienceID,JobFunction) + VALUES + (@ID,@ResumeID,@ResumeExperienceID,@JobFunction) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + ResumeExperienceID = @ResumeExperienceID, + JobFunction = @JobFunction; + "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@ResumeExperienceID", cur.ResumeExperienceID); - cmd.Parameters.AddWithValue("@JobFunction", cur.JobFunction); + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@ID", bullet.ID); + cmd.Parameters.AddWithValue("@ResumeID", bullet.ResumeID); + cmd.Parameters.AddWithValue("@ResumeExperienceID", bullet.ResumeExperienceID); + cmd.Parameters.AddWithValue("@JobFunction", bullet.JobFunction); - await cmd.ExecuteNonQueryAsync(); - } + await cmd.ExecuteNonQueryAsync(); } - public async Task SetResumeExperience(MySqlConnection connection, ResumeExperience[] experiences) { - foreach (ResumeExperience cur in experiences) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,JobTitle,Company,PostalCode,Country,StateOrRegion,City,DateStarted,StillEmployed,DateEnded) - VALUES - (@ID,@ResumeID,@JobTitle,@Company,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillEmployed,@DateEnded) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - JobTitle = @JobTitle, - Company = @Company, - PostalCode = @PostalCode, - Country = @Country, - StateOrRegion = @StateOrRegion, - City = @City, - DateStarted = @DateStarted, - StillEmployed = @StillEmployed, - DateEnded = @DateEnded; + public async Task SetResumeExperience(MySqlConnection connection, ResumeExperience experiences) { + string command = @" + INSERT INTO Resume + (ID,ResumeID,JobTitle,Company,PostalCode,Country,StateOrRegion,City,DateStarted,StillEmployed,DateEnded) + VALUES + (@ID,@ResumeID,@JobTitle,@Company,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillEmployed,@DateEnded) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + JobTitle = @JobTitle, + Company = @Company, + PostalCode = @PostalCode, + Country = @Country, + StateOrRegion = @StateOrRegion, + City = @City, + DateStarted = @DateStarted, + StillEmployed = @StillEmployed, + DateEnded = @DateEnded; - SELECT LAST_INSERT_ID(); - "; + SELECT LAST_INSERT_ID(); + "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@JobTitle", cur.JobTitle); - cmd.Parameters.AddWithValue("@Company", cur.Company); - cmd.Parameters.AddWithValue("@PostalCode", cur.PostalCode); - cmd.Parameters.AddWithValue("@DateStarted", cur.DateStarted.ToUniversalTime()); - cmd.Parameters.AddWithValue("@StillEmployed", cur.StillEmployed); - cmd.Parameters.AddWithValue("@DateEnded", cur.DateEnded.ToUniversalTime()); - object? result = await cmd.ExecuteScalarAsync(); + MySqlCommand cmd = new MySqlCommand(command, connection); + cmd.Parameters.AddWithValue("@ID", experiences.ID); + cmd.Parameters.AddWithValue("@ResumeID", experiences.ResumeID); + cmd.Parameters.AddWithValue("@JobTitle", experiences.JobTitle); + cmd.Parameters.AddWithValue("@Company", experiences.Company); + cmd.Parameters.AddWithValue("@PostalCode", experiences.PostalCode); + cmd.Parameters.AddWithValue("@DateStarted", experiences.DateStarted.ToUniversalTime()); + cmd.Parameters.AddWithValue("@StillEmployed", experiences.StillEmployed); + cmd.Parameters.AddWithValue("@DateEnded", experiences.DateEnded.ToUniversalTime()); + object? result = await cmd.ExecuteScalarAsync(); - if (cur.ID != null && cur.ID != 0) { - return Convert.ToInt32(cur.ID); - } else { - cmd.CommandText = ""; - return Convert.ToInt32(result); - } + if (experiences.ID == null) { + experiences.ID = Convert.ToInt32(result); } + return experiences; } public async Task SetResumeMilitaryBullets(MySqlConnection connection, ResumeMilitaryBullet[] bullets) { @@ -139,7 +133,7 @@ namespace BoredCareers.Services.DatabaseService { } } - public async Task SetResumeMilitary(MySqlConnection connection, ResumeMilitary? military) { + public async Task SetResumeMilitary(MySqlConnection connection, ResumeMilitary? military) { if (military != null) { string command = @" INSERT INTO Resume @@ -167,13 +161,12 @@ namespace BoredCareers.Services.DatabaseService { cmd.Parameters.AddWithValue("@DateEnded", military.DateEnded.ToUniversalTime()); object? result = await cmd.ExecuteScalarAsync(); - if (military.ID != null && military.ID != 0) { - return Convert.ToInt32(military.ID); - } else { - cmd.CommandText = ""; - return Convert.ToInt32(result); + if (military.ID == null) { + military.ID = Convert.ToInt32(result); } + return military; } + return new ResumeMilitary(); } public async Task SetResumeEducation(MySqlConnection connection, ResumeEducation[] educations) { -- 2.52.0 From 2d6644fc0e4c8a778b74a625cb5ee068cba389eb Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 14 Aug 2025 16:52:59 -0700 Subject: [PATCH 4/7] Fix naming Scheme --- src/Client/src/app/models/Resume.ts | 8 ++++---- src/Server/Entities/Resume.cs | 30 ++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Client/src/app/models/Resume.ts b/src/Client/src/app/models/Resume.ts index 9efabed..a3efa7c 100644 --- a/src/Client/src/app/models/Resume.ts +++ b/src/Client/src/app/models/Resume.ts @@ -13,12 +13,12 @@ export class Resume { public stateOrRegion: string = ""; public city: string = ""; public isActive: boolean = false; - public experience: ResumeExperience[] = []; public military: ResumeMilitary | null = new ResumeMilitary; - public education: ResumeEducation[] = []; + public experiences: ResumeExperience[] = []; + public educations: ResumeEducation[] = []; public skills: ResumeSkill[] = []; public languages: ResumeLanguage[] = []; - public certification: ResumeCertification[] = []; + public certifications: ResumeCertification[] = []; public projects: ResumeProject[] = []; public trackUUID: string = crypto.randomUUID(); } @@ -58,7 +58,7 @@ export class ResumeMilitary { public dateStarted: Date = new Date(); public stillServing: boolean = false; public dateEnded: Date = new Date(); - public millitaryBullets: ResumeMilitaryBullet[] = []; + public militaryBullets: ResumeMilitaryBullet[] = []; public trackUUID: string = crypto.randomUUID(); } diff --git a/src/Server/Entities/Resume.cs b/src/Server/Entities/Resume.cs index 069e21d..31fc5db 100644 --- a/src/Server/Entities/Resume.cs +++ b/src/Server/Entities/Resume.cs @@ -12,18 +12,18 @@ namespace BoredCareers.Entities { public string StateOrRegion { get; set; } = ""; public string City { get; set; } = ""; public bool IsActive { get; set; } = false; - public ResumeExperience[] Experience { get; set; } = []; - public ResumeMilitary? Millitary { get; set; } = null; + public ResumeExperience[] Experiences { get; set; } = []; + public ResumeMilitary? Military { get; set; } = null; public ResumeEducation[] Educations { get; set; } = []; public ResumeSkill[] Skills { get; set; } = []; public ResumeLanguage[] Languages { get; set; } = []; - public ResumeCertification[] Certification { get; set; } = []; + public ResumeCertification[] Certifications { get; set; } = []; public ResumeProject[] Projects { get; set; } = []; } public class ResumeExperience { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string JobTitle { get; set; } = ""; public string Company { get; set; } = ""; public string PostalCode { get; set; } = ""; @@ -38,33 +38,33 @@ namespace BoredCareers.Entities { public class ResumeExperienceBullet { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK - public int ResumeExperienceID { get; set; } // FK + public int? ResumeID { get; set; } // FK + public int? ResumeExperienceID { get; set; } // FK public string JobFunction { get; set; } = ""; } public class ResumeMilitary { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string Country { get; set; } = ""; // 2 Letter Country Code public string Rank { get; set; } = ""; public DateTime DateStarted { get; set; } = new DateTime(); public bool StillServing { get; set; } = false; public DateTime DateEnded { get; set; } = new DateTime(); - public ResumeMilitaryBullet[] MillitaryBullets = []; + public ResumeMilitaryBullet[] MilitaryBullets { get; set; } = []; } public class ResumeMilitaryBullet { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK - public int ResumeMilitaryID { get; set; } // FK + public int? ResumeID { get; set; } // FK + public int? ResumeMilitaryID { get; set; } // FK public string Achievement { get; set; } = ""; public string Description { get; set; } = ""; } public class ResumeEducation { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string DegreeType { get; set; } = ""; public string DegreeField { get; set; } = ""; public string School { get; set; } = ""; @@ -79,21 +79,21 @@ namespace BoredCareers.Entities { public class ResumeSkill { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string Name { get; set; } = ""; public string Description { get; set; } = ""; } public class ResumeLanguage { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string Language { get; set; } = ""; public string Proficiency { get; set; } = ""; } public class ResumeCertification { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string Name { get; set; } = ""; public string VerificationURL { get; set; } = ""; public string Description { get; set; } = ""; @@ -101,7 +101,7 @@ namespace BoredCareers.Entities { public class ResumeProject { public int? ID { get; set; } // PK - public int ResumeID { get; set; } // FK + public int? ResumeID { get; set; } // FK public string Name { get; set; } = ""; public string URL { get; set; } = ""; public string Description { get; set; } = ""; -- 2.52.0 From 5ad7ca0c3e7466f456c6a515d68b0638dc6c66a2 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 14 Aug 2025 16:53:07 -0700 Subject: [PATCH 5/7] Get DbDriver Set working --- .../resumes/editor/editor.component.html | 9 +- .../pages/resumes/editor/editor.component.ts | 32 +- src/Server/Services/DatabaseService/Resume.cs | 122 ++-- .../ResumeParts/GetResumeParts.cs | 2 +- .../ResumeParts/SetResumeParts.cs | 539 ++++++++++-------- 5 files changed, 367 insertions(+), 337 deletions(-) diff --git a/src/Client/src/app/pages/resumes/editor/editor.component.html b/src/Client/src/app/pages/resumes/editor/editor.component.html index 179d15c..c520e48 100644 --- a/src/Client/src/app/pages/resumes/editor/editor.component.html +++ b/src/Client/src/app/pages/resumes/editor/editor.component.html @@ -8,6 +8,7 @@ +

Public:

@@ -16,7 +17,7 @@
- @for(experience of resume.experience; track experience.trackUUID ){ + @for(experience of resume.experiences; track experience.trackUUID ){
@@ -53,7 +54,7 @@ } - @for(military of resume.military.millitaryBullets; track military.trackUUID ){ + @for(military of resume.military.militaryBullets; track military.trackUUID ){
@@ -66,7 +67,7 @@
- @for(education of resume.education; track education.trackUUID){ + @for(education of resume.educations; track education.trackUUID){
@@ -113,7 +114,7 @@
- @for(cert of resume.certification; track cert.trackUUID){ + @for(cert of resume.certifications; track cert.trackUUID){
diff --git a/src/Client/src/app/pages/resumes/editor/editor.component.ts b/src/Client/src/app/pages/resumes/editor/editor.component.ts index f7aa2f0..925131e 100644 --- a/src/Client/src/app/pages/resumes/editor/editor.component.ts +++ b/src/Client/src/app/pages/resumes/editor/editor.component.ts @@ -57,13 +57,13 @@ export class ResumesEditorComponent { } addExperience(){ - this.resume.experience.push( new ResumeExperience ); + this.resume.experiences.push( new ResumeExperience ); } delExperience(self: ResumeExperience){ - for(let i=0; i[] tasks = [ @@ -94,21 +94,21 @@ namespace BoredCareers.Services.DatabaseService { ResumeCertification[] certs = await GetResumeCertification(await tasks[7]); ResumeProject[] projects = await GetResumeProjects(await tasks[8]); - Dictionary groupedExperienceBullets = bullets.GroupBy(b => b.ResumeExperienceID).ToDictionary(g => g.Key, g => g.ToArray()); + Dictionary groupedExperienceBullets = bullets.GroupBy(b => Convert.ToInt32(b.ResumeExperienceID)).ToDictionary(g => g.Key, g => g.ToArray()); foreach (var exp in experience) { exp.ExperienceBullets = groupedExperienceBullets.TryGetValue(Convert.ToInt32(exp.ID), out var b) ? b : Array.Empty(); } - resume.Experience = experience; + resume.Experiences = experience; resume.Educations = education; resume.Skills = skills; resume.Languages = languages; - resume.Certification = certs; + resume.Certifications = certs; resume.Projects = projects; if (military != null) { - military.MillitaryBullets = militaryBullets; - resume.Millitary = military; + military.MilitaryBullets = militaryBullets; + resume.Military = military; } return resume; @@ -116,66 +116,62 @@ namespace BoredCareers.Services.DatabaseService { } public async Task SetResume(Resume resume) { - using (var conn = GetConnection()) { - await conn.OpenAsync(); - - // Set ResumeID on all nodes - int _ResumeID = await SetResume(conn, resume); - if (resume.Millitary != null) { - resume.Millitary.ResumeID = _ResumeID; - foreach (ResumeMilitaryBullet cur in resume.Millitary.MillitaryBullets) { - cur.ResumeID = _ResumeID; - } - } - foreach (ResumeEducation cur in resume.Educations) { cur.ResumeID = _ResumeID; } - foreach (ResumeSkill cur in resume.Skills) { cur.ResumeID = _ResumeID; } - foreach (ResumeLanguage cur in resume.Languages) { cur.ResumeID = _ResumeID; } - foreach (ResumeCertification cur in resume.Certification) { cur.ResumeID = _ResumeID; } - foreach (ResumeProject cur in resume.Projects) { cur.ResumeID = _ResumeID; } - foreach (ResumeExperience cur in resume.Experience) { + // Set ResumeID on all nodes + int _ResumeID = await SetResumeHeader(resume); + if (resume.Military != null) { + resume.Military.ResumeID = _ResumeID; + foreach (ResumeMilitaryBullet cur in resume.Military.MilitaryBullets) { cur.ResumeID = _ResumeID; - foreach (ResumeExperienceBullet us in cur.ExperienceBullets) { - us.ResumeID = _ResumeID; - } } - - // Async process all non child node SQL sets - Task[] tasks = [ - SetResumeEducation(conn, resume.Educations), - SetResumeSkills(conn, resume.Skills), - SetResumeLanguages(conn, resume.Languages), - SetResumeCertification(conn, resume.Certification), - SetResumeProjects(conn, resume.Projects) - ]; - await Task.WhenAll(tasks); - - // Setup military task - if (resume.Millitary != null) { - ResumeMilitary militaryTask = await SetResumeMilitary(conn, resume.Millitary); - foreach (ResumeMilitaryBullet cur in resume.Millitary.MillitaryBullets) { - cur.ResumeMilitaryID = Convert.ToInt32(militaryTask.ID); - } - await SetResumeMilitaryBullets(conn, resume.Millitary.MillitaryBullets); - } - - // Setup async process all experience tasks - List> experienceTasks = new List>(); - foreach (ResumeExperience cur in resume.Experience) { - experienceTasks.Add(SetResumeExperience(conn, cur)); - } - await Task.WhenAll(experienceTasks); - - // Assuming they are returned in the same order they are sent - List experienceBulletTasks = new List(); - for (int i = 0; i < experienceTasks.Count; i++) { - ResumeExperience self = await experienceTasks[i]; - foreach (ResumeExperienceBullet cur in resume.Experience[i].ExperienceBullets) { - cur.ResumeExperienceID = Convert.ToInt32(self.ID); - experienceBulletTasks.Add(SetResumeExperienceBullets(conn, cur)); - } - } - await Task.WhenAll(experienceBulletTasks); } + foreach (ResumeEducation cur in resume.Educations) { cur.ResumeID = _ResumeID; } + foreach (ResumeSkill cur in resume.Skills) { cur.ResumeID = _ResumeID; } + foreach (ResumeLanguage cur in resume.Languages) { cur.ResumeID = _ResumeID; } + foreach (ResumeCertification cur in resume.Certifications) { cur.ResumeID = _ResumeID; } + foreach (ResumeProject cur in resume.Projects) { cur.ResumeID = _ResumeID; } + foreach (ResumeExperience cur in resume.Experiences) { + cur.ResumeID = _ResumeID; + foreach (ResumeExperienceBullet us in cur.ExperienceBullets) { + us.ResumeID = _ResumeID; + } + } + + // Async process all non child node SQL sets + Task[] tasks = [ + SetResumeEducation(resume.Educations), + SetResumeSkills(resume.Skills), + SetResumeLanguages(resume.Languages), + SetResumeCertification(resume.Certifications), + SetResumeProjects(resume.Projects) + ]; + await Task.WhenAll(tasks); + + // Setup military task + if (resume.Military != null) { + ResumeMilitary militaryTask = await SetResumeMilitary(resume.Military); + foreach (ResumeMilitaryBullet cur in resume.Military.MilitaryBullets) { + cur.ResumeMilitaryID = Convert.ToInt32(militaryTask.ID); + } + await SetResumeMilitaryBullets(resume.Military.MilitaryBullets); + } + + // Setup async process all experience tasks + List> experienceTasks = new List>(); + foreach (ResumeExperience cur in resume.Experiences) { + experienceTasks.Add(SetResumeExperience(cur)); + } + await Task.WhenAll(experienceTasks); + + // Assuming they are returned in the same order they are sent + List experienceBulletTasks = new List(); + for (int i = 0; i < experienceTasks.Count; i++) { + ResumeExperience self = await experienceTasks[i]; + foreach (ResumeExperienceBullet cur in resume.Experiences[i].ExperienceBullets) { + cur.ResumeExperienceID = Convert.ToInt32(self.ID); + experienceBulletTasks.Add(SetResumeExperienceBullets(cur)); + } + } + await Task.WhenAll(experienceBulletTasks); } public async Task DeleteResume( int ResumeID ) { diff --git a/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs b/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs index 152e5e3..b0f4409 100644 --- a/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs +++ b/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs @@ -5,7 +5,7 @@ using System.Data.Common; namespace BoredCareers.Services.DatabaseService { public partial class DatabaseService { - public async Task GetResume(DbDataReader reader) { + public async Task GetResumeHeader(DbDataReader reader) { while (await reader.ReadAsync()) { if (reader == null) { break; } int _id = reader.GetInt32("ID"); diff --git a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs index 47054ab..2c4833e 100644 --- a/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs +++ b/src/Server/Services/DatabaseService/ResumeParts/SetResumeParts.cs @@ -4,303 +4,336 @@ using MySql.Data.MySqlClient; namespace BoredCareers.Services.DatabaseService { public partial class DatabaseService { - public async Task SetResume(MySqlConnection connection, Resume resume) { - string command = @" - INSERT INTO Resume - (ID,AccountID,Title,Name,Field,Email,PhoneNumber,PostalCode,Country,StateOrRegion,City,IsActive) - VALUES - (@ID,@AccountID,@Title,@Name,@Field,@Email,@PhoneNumber,@PostalCode,@Country,@StateOrRegion,@City,@IsActive) - ON DUPLICATE KEY UPDATE - AccountID = @AccountID, - Title = @Title, - Name = @Name, - Field = @Field, - Email = @Email, - PhoneNumber = @PhoneNumber, - PostalCode = @PostalCode, - Country = @Country, - StateOrRegion = @StateOrRegion, - City = @City, - IsActive = @IsActive; - - SELECT LAST_INSERT_ID(); - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", resume.ID); - cmd.Parameters.AddWithValue("@AccountID", resume.AccountID); - cmd.Parameters.AddWithValue("@Title", resume.Title); - cmd.Parameters.AddWithValue("@Name", resume.Name); - cmd.Parameters.AddWithValue("@Field", resume.Field); - cmd.Parameters.AddWithValue("@Email", resume.Email); - cmd.Parameters.AddWithValue("@PhoneNumber", resume.PhoneNumber); - cmd.Parameters.AddWithValue("@PostalCode", resume.PostalCode); - cmd.Parameters.AddWithValue("@Country", resume.Country); - cmd.Parameters.AddWithValue("@StateOrRegion", resume.StateOrRegion); - cmd.Parameters.AddWithValue("@City", resume.City); - cmd.Parameters.AddWithValue("@IsActive", resume.IsActive); - object? result = await cmd.ExecuteScalarAsync(); - - if (resume.ID != null && resume.ID != 0) { - return Convert.ToInt32(resume.ID); - } else { - cmd.CommandText = ""; - return Convert.ToInt32(result); - } - } - - public async Task SetResumeExperienceBullets(MySqlConnection connection, ResumeExperienceBullet bullet) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,ResumeExperienceID,JobFunction) - VALUES - (@ID,@ResumeID,@ResumeExperienceID,@JobFunction) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - ResumeExperienceID = @ResumeExperienceID, - JobFunction = @JobFunction; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", bullet.ID); - cmd.Parameters.AddWithValue("@ResumeID", bullet.ResumeID); - cmd.Parameters.AddWithValue("@ResumeExperienceID", bullet.ResumeExperienceID); - cmd.Parameters.AddWithValue("@JobFunction", bullet.JobFunction); - - await cmd.ExecuteNonQueryAsync(); - } - - public async Task SetResumeExperience(MySqlConnection connection, ResumeExperience experiences) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,JobTitle,Company,PostalCode,Country,StateOrRegion,City,DateStarted,StillEmployed,DateEnded) - VALUES - (@ID,@ResumeID,@JobTitle,@Company,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillEmployed,@DateEnded) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - JobTitle = @JobTitle, - Company = @Company, - PostalCode = @PostalCode, - Country = @Country, - StateOrRegion = @StateOrRegion, - City = @City, - DateStarted = @DateStarted, - StillEmployed = @StillEmployed, - DateEnded = @DateEnded; - - SELECT LAST_INSERT_ID(); - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", experiences.ID); - cmd.Parameters.AddWithValue("@ResumeID", experiences.ResumeID); - cmd.Parameters.AddWithValue("@JobTitle", experiences.JobTitle); - cmd.Parameters.AddWithValue("@Company", experiences.Company); - cmd.Parameters.AddWithValue("@PostalCode", experiences.PostalCode); - cmd.Parameters.AddWithValue("@DateStarted", experiences.DateStarted.ToUniversalTime()); - cmd.Parameters.AddWithValue("@StillEmployed", experiences.StillEmployed); - cmd.Parameters.AddWithValue("@DateEnded", experiences.DateEnded.ToUniversalTime()); - object? result = await cmd.ExecuteScalarAsync(); - - if (experiences.ID == null) { - experiences.ID = Convert.ToInt32(result); - } - return experiences; - } - - public async Task SetResumeMilitaryBullets(MySqlConnection connection, ResumeMilitaryBullet[] bullets) { - foreach (ResumeMilitaryBullet cur in bullets) { + public async Task SetResumeHeader(Resume resume) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); string command = @" INSERT INTO Resume - (ID,ResumeID,ResumeMilitaryID,Achievement) + (ID,AccountID,Title,Name,Field,Email,PhoneNumber,PostalCode,Country,StateOrRegion,City,IsActive) VALUES - (@ID,@ResumeID,@ResumeMilitaryID,@Achievement) + (@ID,@AccountID,@Title,@Name,@Field,@Email,@PhoneNumber,@PostalCode,@Country,@StateOrRegion,@City,@IsActive) ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - ResumeMilitaryID = @ResumeMilitaryID, - Achievement = @Achievement, - Description = @Description; + AccountID = @AccountID, + Title = @Title, + Name = @Name, + Field = @Field, + Email = @Email, + PhoneNumber = @PhoneNumber, + PostalCode = @PostalCode, + Country = @Country, + StateOrRegion = @StateOrRegion, + City = @City, + IsActive = @IsActive; + + SELECT LAST_INSERT_ID(); "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@ResumeMilitaryID", cur.ResumeMilitaryID); - cmd.Parameters.AddWithValue("@Achievement", cur.Achievement); - cmd.Parameters.AddWithValue("@Description", cur.Description); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", resume.ID); + cmd.Parameters.AddWithValue("@AccountID", resume.AccountID); + cmd.Parameters.AddWithValue("@Title", resume.Title); + cmd.Parameters.AddWithValue("@Name", resume.Name); + cmd.Parameters.AddWithValue("@Field", resume.Field); + cmd.Parameters.AddWithValue("@Email", resume.Email); + cmd.Parameters.AddWithValue("@PhoneNumber", resume.PhoneNumber); + cmd.Parameters.AddWithValue("@PostalCode", resume.PostalCode); + cmd.Parameters.AddWithValue("@Country", resume.Country); + cmd.Parameters.AddWithValue("@StateOrRegion", resume.StateOrRegion); + cmd.Parameters.AddWithValue("@City", resume.City); + cmd.Parameters.AddWithValue("@IsActive", resume.IsActive); + object? result = await cmd.ExecuteScalarAsync(); + + if (resume.ID != null && resume.ID != 0) { + return Convert.ToInt32(resume.ID); + } else { + cmd.CommandText = ""; + return Convert.ToInt32(result); + } + } + } + + public async Task SetResumeExperienceBullets(ResumeExperienceBullet bullet) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + string command = @" + INSERT INTO ResumeExperienceBullet + (ID,ResumeID,ResumeExperienceID,JobFunction) + VALUES + (@ID,@ResumeID,@ResumeExperienceID,@JobFunction) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + ResumeExperienceID = @ResumeExperienceID, + JobFunction = @JobFunction; + "; + + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", bullet.ID); + cmd.Parameters.AddWithValue("@ResumeID", bullet.ResumeID); + cmd.Parameters.AddWithValue("@ResumeExperienceID", bullet.ResumeExperienceID); + cmd.Parameters.AddWithValue("@JobFunction", bullet.JobFunction); await cmd.ExecuteNonQueryAsync(); } } - public async Task SetResumeMilitary(MySqlConnection connection, ResumeMilitary? military) { - if (military != null) { + public async Task SetResumeExperience(ResumeExperience experiences) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); string command = @" - INSERT INTO Resume - (ID,ResumeID,Country,Rank,DateStarted,StillServing,DateEnded) + INSERT INTO ResumeExperience + (ID,ResumeID,JobTitle,Company,PostalCode,Country,StateOrRegion,City,DateStarted,StillEmployed,DateEnded) VALUES - (@ID,@ResumeID,@Country,@Rank,@DateStarted,@StillServing,@DateEnded) + (@ID,@ResumeID,@JobTitle,@Company,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillEmployed,@DateEnded) ON DUPLICATE KEY UPDATE ResumeID = @ResumeID, - Country = @Country, - Rank = @Rank, - DateStarted = @DateStarted, - StillServing = @StillServing, - DateEnded = @DateEnded; - - SELECT LAST_INSERT_ID(); - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", military.ID); - cmd.Parameters.AddWithValue("@ResumeID", military.ResumeID); - cmd.Parameters.AddWithValue("@Country", military.Country); - cmd.Parameters.AddWithValue("@Rank", military.Rank); - cmd.Parameters.AddWithValue("@DateStarted", military.DateStarted.ToUniversalTime()); - cmd.Parameters.AddWithValue("@StillServing", military.StillServing); - cmd.Parameters.AddWithValue("@DateEnded", military.DateEnded.ToUniversalTime()); - object? result = await cmd.ExecuteScalarAsync(); - - if (military.ID == null) { - military.ID = Convert.ToInt32(result); - } - return military; - } - return new ResumeMilitary(); - } - - public async Task SetResumeEducation(MySqlConnection connection, ResumeEducation[] educations) { - foreach (ResumeEducation cur in educations) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,DegreeType,DegreeField,School,PostalCode,Country,StateOrRegion,City,DateStarted,StillStudying,DateEnded) - VALUES - (@ID,@ResumeID,@DegreeType,@DegreeField,@School,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillStudying,@DateEnded) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - DegreeType = @DegreeType, - DegreeField = @DegreeField, - School = @School, + JobTitle = @JobTitle, + Company = @Company, PostalCode = @PostalCode, Country = @Country, StateOrRegion = @StateOrRegion, City = @City, DateStarted = @DateStarted, - StillStudying = @StillStudying, + StillEmployed = @StillEmployed, DateEnded = @DateEnded; + + SELECT LAST_INSERT_ID(); "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@DegreeType", cur.DegreeType); - cmd.Parameters.AddWithValue("@DegreeField", cur.DegreeField); - cmd.Parameters.AddWithValue("@School", cur.School); - cmd.Parameters.AddWithValue("@PostalCode", cur.PostalCode); - cmd.Parameters.AddWithValue("@Country", cur.Country); - cmd.Parameters.AddWithValue("@StateOrRegion", cur.StateOrRegion); - cmd.Parameters.AddWithValue("@City", cur.City); - cmd.Parameters.AddWithValue("@DateStarted", cur.DateStarted.ToUniversalTime()); - cmd.Parameters.AddWithValue("@StillStudying", cur.StillStudying); - cmd.Parameters.AddWithValue("@DateEnded", cur.DateEnded.ToUniversalTime()); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", experiences.ID); + cmd.Parameters.AddWithValue("@ResumeID", experiences.ResumeID); + cmd.Parameters.AddWithValue("@JobTitle", experiences.JobTitle); + cmd.Parameters.AddWithValue("@Company", experiences.Company); + cmd.Parameters.AddWithValue("@Country", experiences.Country); + cmd.Parameters.AddWithValue("@StateOrRegion", experiences.StateOrRegion); + cmd.Parameters.AddWithValue("@City", experiences.City); + cmd.Parameters.AddWithValue("@PostalCode", experiences.PostalCode); + cmd.Parameters.AddWithValue("@DateStarted", experiences.DateStarted.ToUniversalTime()); + cmd.Parameters.AddWithValue("@StillEmployed", experiences.StillEmployed); + cmd.Parameters.AddWithValue("@DateEnded", experiences.DateEnded.ToUniversalTime()); + object? result = await cmd.ExecuteScalarAsync(); - await cmd.ExecuteNonQueryAsync(); + if (experiences.ID == null) { + experiences.ID = Convert.ToInt32(result); + } + return experiences; } } - public async Task SetResumeSkills(MySqlConnection connection, ResumeSkill[] skills) { - foreach (ResumeSkill cur in skills) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,Name,Description) - VALUES - (@ID,@ResumeID,@Name,@Description) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - Name = @Name, - Description = @Description; - "; + public async Task SetResumeMilitaryBullets(ResumeMilitaryBullet[] bullets) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeMilitaryBullet cur in bullets) { + string command = @" + INSERT INTO ResumeMilitaryBullet + (ID,ResumeID,ResumeMilitaryID,Achievement) + VALUES + (@ID,@ResumeID,@ResumeMilitaryID,@Achievement) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + ResumeMilitaryID = @ResumeMilitaryID, + Achievement = @Achievement, + Description = @Description; + "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@Name", cur.Name); - cmd.Parameters.AddWithValue("@Description", cur.Description); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@ResumeMilitaryID", cur.ResumeMilitaryID); + cmd.Parameters.AddWithValue("@Achievement", cur.Achievement); + cmd.Parameters.AddWithValue("@Description", cur.Description); - await cmd.ExecuteNonQueryAsync(); + await cmd.ExecuteNonQueryAsync(); + } } } - public async Task SetResumeLanguages(MySqlConnection connection, ResumeLanguage[] languages) { - foreach (ResumeLanguage cur in languages) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,Language,Proficiency) - VALUES - (@ID,@ResumeID,@Language,@Proficiency) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - Language = @Language, - Proficiency = @Proficiency; - "; + public async Task SetResumeMilitary(ResumeMilitary? military) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + if (military != null) { + string command = @" + INSERT INTO ResumeMilitary + (ID,ResumeID,Country,`Rank`,DateStarted,StillServing,DateEnded) + VALUES + (@ID,@ResumeID,@Country,@Rank,@DateStarted,@StillServing,@DateEnded) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Country = @Country, + `Rank` = @Rank, + DateStarted = @DateStarted, + StillServing = @StillServing, + DateEnded = @DateEnded; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@Language", cur.Language); - cmd.Parameters.AddWithValue("@Proficiency", cur.Proficiency); + SELECT LAST_INSERT_ID(); + "; - await cmd.ExecuteNonQueryAsync(); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", military.ID); + cmd.Parameters.AddWithValue("@ResumeID", military.ResumeID); + cmd.Parameters.AddWithValue("@Country", military.Country); + cmd.Parameters.AddWithValue("@Rank", military.Rank); + cmd.Parameters.AddWithValue("@DateStarted", military.DateStarted.ToUniversalTime()); + cmd.Parameters.AddWithValue("@StillServing", military.StillServing); + cmd.Parameters.AddWithValue("@DateEnded", military.DateEnded.ToUniversalTime()); + object? result = await cmd.ExecuteScalarAsync(); + + if (military.ID == null) { + military.ID = Convert.ToInt32(result); + } + return military; + } + return new ResumeMilitary(); } } - public async Task SetResumeCertification(MySqlConnection connection, ResumeCertification[] certifications) { - foreach (ResumeCertification cur in certifications) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,Name,VerificationURL,Description) - VALUES - (@ID,@ResumeID,@Name,@VerificationURL,@Description) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - Name = @DegreeNameType, - VerificationURL = @VerificationURL, - Description = @Description; - "; + public async Task SetResumeEducation(ResumeEducation[] educations) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeEducation cur in educations) { + string command = @" + INSERT INTO ResumeEducation + (ID,ResumeID,DegreeType,DegreeField,School,PostalCode,Country,StateOrRegion,City,DateStarted,StillStudying,DateEnded) + VALUES + (@ID,@ResumeID,@DegreeType,@DegreeField,@School,@PostalCode,@Country,@StateOrRegion,@City,@DateStarted,@StillStudying,@DateEnded) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + DegreeType = @DegreeType, + DegreeField = @DegreeField, + School = @School, + PostalCode = @PostalCode, + Country = @Country, + StateOrRegion = @StateOrRegion, + City = @City, + DateStarted = @DateStarted, + StillStudying = @StillStudying, + DateEnded = @DateEnded; + "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@Name", cur.Name); - cmd.Parameters.AddWithValue("@VerificationURL", cur.VerificationURL); - cmd.Parameters.AddWithValue("@Description", cur.Description); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@DegreeType", cur.DegreeType); + cmd.Parameters.AddWithValue("@DegreeField", cur.DegreeField); + cmd.Parameters.AddWithValue("@School", cur.School); + cmd.Parameters.AddWithValue("@PostalCode", cur.PostalCode); + cmd.Parameters.AddWithValue("@Country", cur.Country); + cmd.Parameters.AddWithValue("@StateOrRegion", cur.StateOrRegion); + cmd.Parameters.AddWithValue("@City", cur.City); + cmd.Parameters.AddWithValue("@DateStarted", cur.DateStarted.ToUniversalTime()); + cmd.Parameters.AddWithValue("@StillStudying", cur.StillStudying); + cmd.Parameters.AddWithValue("@DateEnded", cur.DateEnded.ToUniversalTime()); - await cmd.ExecuteNonQueryAsync(); + await cmd.ExecuteNonQueryAsync(); + } } } - public async Task SetResumeProjects(MySqlConnection connection, ResumeProject[] projects) { - foreach (ResumeProject cur in projects) { - string command = @" - INSERT INTO Resume - (ID,ResumeID,Name,URL,Description) - VALUES - (@ID,@ResumeID,@Name,@URL,@Description) - ON DUPLICATE KEY UPDATE - ResumeID = @ResumeID, - Name = @Name, - URL = @URL, - Description = @Description; - "; + public async Task SetResumeSkills(ResumeSkill[] skills) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeSkill cur in skills) { + string command = @" + INSERT INTO ResumeSkill + (ID,ResumeID,Name,Description) + VALUES + (@ID,@ResumeID,@Name,@Description) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Name = @Name, + Description = @Description; + "; - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", cur.ID); - cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); - cmd.Parameters.AddWithValue("@Name", cur.Name); - cmd.Parameters.AddWithValue("@URL", cur.URL); - cmd.Parameters.AddWithValue("@Description", cur.Description); + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@Name", cur.Name); + cmd.Parameters.AddWithValue("@Description", cur.Description); - await cmd.ExecuteNonQueryAsync(); + await cmd.ExecuteNonQueryAsync(); + } + } + } + + public async Task SetResumeLanguages(ResumeLanguage[] languages) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeLanguage cur in languages) { + string command = @" + INSERT INTO ResumeLanguage + (ID,ResumeID,Language,Proficiency) + VALUES + (@ID,@ResumeID,@Language,@Proficiency) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Language = @Language, + Proficiency = @Proficiency; + "; + + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@Language", cur.Language); + cmd.Parameters.AddWithValue("@Proficiency", cur.Proficiency); + + await cmd.ExecuteNonQueryAsync(); + } + } + } + + public async Task SetResumeCertification(ResumeCertification[] certifications) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeCertification cur in certifications) { + string command = @" + INSERT INTO ResumeCertification + (ID,ResumeID,Name,VerificationURL,Description) + VALUES + (@ID,@ResumeID,@Name,@VerificationURL,@Description) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Name = @Name, + VerificationURL = @VerificationURL, + Description = @Description; + "; + + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@Name", cur.Name); + cmd.Parameters.AddWithValue("@VerificationURL", cur.VerificationURL); + cmd.Parameters.AddWithValue("@Description", cur.Description); + + await cmd.ExecuteNonQueryAsync(); + } + } + } + + public async Task SetResumeProjects(ResumeProject[] projects) { + using (var conn = GetConnection()) { + await conn.OpenAsync(); + foreach (ResumeProject cur in projects) { + string command = @" + INSERT INTO ResumeProject + (ID,ResumeID,Name,URL,Description) + VALUES + (@ID,@ResumeID,@Name,@URL,@Description) + ON DUPLICATE KEY UPDATE + ResumeID = @ResumeID, + Name = @Name, + URL = @URL, + Description = @Description; + "; + + MySqlCommand cmd = new MySqlCommand(command, conn); + cmd.Parameters.AddWithValue("@ID", cur.ID); + cmd.Parameters.AddWithValue("@ResumeID", cur.ResumeID); + cmd.Parameters.AddWithValue("@Name", cur.Name); + cmd.Parameters.AddWithValue("@URL", cur.URL); + cmd.Parameters.AddWithValue("@Description", cur.Description); + + await cmd.ExecuteNonQueryAsync(); + } } } -- 2.52.0 From 98604c7d3eda03ab9ddf9f4ba59c693033f3e478 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 14 Aug 2025 20:59:55 -0700 Subject: [PATCH 6/7] Fix UI Breaking --- ToDo.yaml | 6 +- src/Client/src/app/models/Resume.ts | 2 +- .../resumes/editor/editor.component.html | 96 +++++++++---------- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/ToDo.yaml b/ToDo.yaml index f162401..148fba8 100755 --- a/ToDo.yaml +++ b/ToDo.yaml @@ -24,6 +24,9 @@ Server: Server.csproj: Find a way to keep all the libraries up to date + DbDriver: + Make getConnection() -> Based on a connection pool so that more than a specific number of connections cannot be made + Client: jobs/editor: Job Listing Skills exists but isn't implimented in the UI @@ -50,7 +53,8 @@ Client: resume/editor: Not fully tested yet - Veteran needs to be moved from the Resume/millitary into the Resume so it doesnt have to save the whole millitary object to the db if not needed + When adding new fields the fields above it glitch out and disappear + There is no data validation Company: Need to impliment Add employee diff --git a/src/Client/src/app/models/Resume.ts b/src/Client/src/app/models/Resume.ts index a3efa7c..f310a43 100644 --- a/src/Client/src/app/models/Resume.ts +++ b/src/Client/src/app/models/Resume.ts @@ -13,7 +13,7 @@ export class Resume { public stateOrRegion: string = ""; public city: string = ""; public isActive: boolean = false; - public military: ResumeMilitary | null = new ResumeMilitary; + public military: ResumeMilitary | null = null; public experiences: ResumeExperience[] = []; public educations: ResumeEducation[] = []; public skills: ResumeSkill[] = []; diff --git a/src/Client/src/app/pages/resumes/editor/editor.component.html b/src/Client/src/app/pages/resumes/editor/editor.component.html index c520e48..15c06d1 100644 --- a/src/Client/src/app/pages/resumes/editor/editor.component.html +++ b/src/Client/src/app/pages/resumes/editor/editor.component.html @@ -2,16 +2,16 @@
- - - - - - - - - -

Public:

+ + + + + + + + + +

Public:

@@ -19,21 +19,21 @@ @for(experience of resume.experiences; track experience.trackUUID ){
- - - - - - - - + + + + + + + + @if(!experience.stillEmployed){ - + } @for(bullet of experience.experienceBullets; track bullet.trackUUID){
- +
} @@ -44,20 +44,20 @@
-

Is Veteran:

+

Is Veteran:

@if(resume.military !== null){ - - - -

Still Serving:

+ + + +

Still Serving:

@if (!resume.military.stillServing){ - + } @for(military of resume.military.militaryBullets; track military.trackUUID ){
- - + +
} @@ -69,17 +69,17 @@ @for(education of resume.educations; track education.trackUUID){
- - - - - - - - - + + + + + + + + + @if (!education.stillStudying){ - + }
@@ -91,8 +91,8 @@ @for(skill of resume.skills; track skill.trackUUID){
- - + +
} @@ -103,8 +103,8 @@ @for(language of resume.languages; track language.trackUUID){
- - + +
} @@ -116,9 +116,9 @@ @for(cert of resume.certifications; track cert.trackUUID){
- - - + + +
} @@ -129,9 +129,9 @@ @for(proj of resume.projects; track proj.trackUUID){
- - - + + +
} -- 2.52.0 From 06a16a1b05bbb0b2c0bf114f9d9af8d52a098279 Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 14 Aug 2025 21:50:04 -0700 Subject: [PATCH 7/7] Fix DbDriver ResumeGet --- .../app/pages/resumes/resumes.component.html | 4 +- src/Server/Services/DatabaseService/Resume.cs | 63 +-- .../ResumeParts/GetResumeParts.cs | 452 ++++++++++-------- 3 files changed, 296 insertions(+), 223 deletions(-) diff --git a/src/Client/src/app/pages/resumes/resumes.component.html b/src/Client/src/app/pages/resumes/resumes.component.html index 0e9fe97..260a897 100644 --- a/src/Client/src/app/pages/resumes/resumes.component.html +++ b/src/Client/src/app/pages/resumes/resumes.component.html @@ -1,6 +1,8 @@
@for(resume of myResumes; track myResumes.length){ - + @if (resume.id != null){ + + } }
diff --git a/src/Server/Services/DatabaseService/Resume.cs b/src/Server/Services/DatabaseService/Resume.cs index 27e1254..10cee22 100644 --- a/src/Server/Services/DatabaseService/Resume.cs +++ b/src/Server/Services/DatabaseService/Resume.cs @@ -58,41 +58,48 @@ namespace BoredCareers.Services.DatabaseService { return resumes.ToArray(); } - private async Task ExecuteReaderAsync(MySqlConnection conn, string query, int resumeId) { - var cmd = new MySqlCommand(query, conn); - cmd.Parameters.AddWithValue("@ResumeID", resumeId); - return await cmd.ExecuteReaderAsync(); - } - public async Task GetResume(int ResumeID) { using (var conn = GetConnection()) { await conn.OpenAsync(); - Resume? resume = await GetResumeHeader(await ExecuteReaderAsync(conn, "SELECT * FROM Resume WHERE ID = @ResumeID;", ResumeID)); + // Check if resume header exists + Resume? resume = await GetResumeHeader(ResumeID); if (resume == null) { return null; } - Task[] tasks = [ - ExecuteReaderAsync(conn, "SELECT * FROM ResumeExperience WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeExperienceBullet WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeMilitary WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeMilitaryBullet WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeEducation WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeSkill WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeLanguage WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeCertification WHERE ResumeID = @ResumeID;", ResumeID), - ExecuteReaderAsync(conn, "SELECT * FROM ResumeProject WHERE ResumeID = @ResumeID;", ResumeID), - ]; - await Task.WhenAll(tasks); + // Create parallel threads + Task experienceTask = GetResumeExperience(ResumeID); + Task experienceBulletsTask = GetResumeExperienceBullets(ResumeID); + Task militaryTask = GetResumeMilitary(ResumeID); + Task militaryBulletsTask = GetResumeMilitaryBullets(ResumeID); + Task educationTask = GetResumeEducation(ResumeID); + Task skillsTask = GetResumeSkills(ResumeID); + Task languagesTask = GetResumeLanguages(ResumeID); + Task certificationTask = GetResumeCertification(ResumeID); + Task projectsTask = GetResumeProjects(ResumeID); - ResumeExperience[] experience = await GetResumeExperience(await tasks[0]); - ResumeExperienceBullet[] bullets = await GetResumeExperienceBullets(await tasks[1]); - ResumeMilitary? military = await GetResumeMilitary(await tasks[2]); - ResumeMilitaryBullet[] militaryBullets = await GetResumeMilitaryBullets(await tasks[3]); - ResumeEducation[] education = await GetResumeEducation(await tasks[4]); - ResumeSkill[] skills = await GetResumeSkills(await tasks[5]); - ResumeLanguage[] languages = await GetResumeLanguages(await tasks[6]); - ResumeCertification[] certs = await GetResumeCertification(await tasks[7]); - ResumeProject[] projects = await GetResumeProjects(await tasks[8]); + // Run all in parallel + await Task.WhenAll( + experienceTask, + experienceBulletsTask, + militaryTask, + militaryBulletsTask, + educationTask, + skillsTask, + languagesTask, + certificationTask, + projectsTask + ); + + // Get results from parallel processes + ResumeExperience[] experience = await experienceTask; + ResumeExperienceBullet[] bullets = await experienceBulletsTask; + ResumeMilitary? military = await militaryTask; + ResumeMilitaryBullet[] militaryBullets = await militaryBulletsTask; + ResumeEducation[] education = await educationTask; + ResumeSkill[] skills = await skillsTask; + ResumeLanguage[] languages = await languagesTask; + ResumeCertification[] certs = await certificationTask; + ResumeProject[] projects = await projectsTask; Dictionary groupedExperienceBullets = bullets.GroupBy(b => Convert.ToInt32(b.ResumeExperienceID)).ToDictionary(g => g.Key, g => g.ToArray()); foreach (var exp in experience) { diff --git a/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs b/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs index b0f4409..a4c9d7a 100644 --- a/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs +++ b/src/Server/Services/DatabaseService/ResumeParts/GetResumeParts.cs @@ -1,246 +1,310 @@ 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 GetResumeHeader(DbDataReader reader) { - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _accountid = reader.GetInt32("AccountID"); - string _title = reader.GetString("Title"); - string _name = reader.GetString("Name"); - string _field = reader.GetString("Field"); - string _email = reader.GetString("Email"); - string _phonenumber = reader.GetString("PhoneNumber"); - string _postalcode = reader.GetString("PostalCode"); - string _country = reader.GetString("Country"); - string _state = reader.GetString("StateOrRegion"); - string _city = reader.GetString("City"); - bool _isactive = reader.GetBoolean("IsActive"); - return new Resume() { - ID = _id, - AccountID = _accountid, - Title = _title, - Name = _name, - Field = _field, - Email = _email, - PhoneNumber = _phonenumber, - PostalCode = _postalcode, - Country = _country, - StateOrRegion = _state, - City = _city, - IsActive = _isactive - }; + string GetString(DbDataReader reader, string name) { + return reader.IsDBNull(reader.GetOrdinal(name)) ? "" : reader.GetString(name); + } + + public async Task GetResumeHeader(int ResumeID) { + using (MySqlConnection connection = GetConnection()) { + await connection.OpenAsync(); + MySqlCommand cmd = new MySqlCommand("SELECT * FROM Resume WHERE ID = @ID;", connection); + cmd.Parameters.AddWithValue("@ID", ResumeID); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _accountid = reader.GetInt32("AccountID"); + string _title = GetString(reader, "Title"); + string _name = GetString(reader, "Name"); + string _field = GetString(reader, "Field"); + string _email = GetString(reader, "Email"); + string _phonenumber = GetString(reader, "PhoneNumber"); + string _postalcode = GetString(reader, "PostalCode"); + string _country = GetString(reader, "Country"); + string _state = GetString(reader, "StateOrRegion"); + string _city = GetString(reader, "City"); + bool _isactive = reader.GetBoolean("IsActive"); + return new Resume() { + ID = _id, + AccountID = _accountid, + Title = _title, + Name = _name, + Field = _field, + Email = _email, + PhoneNumber = _phonenumber, + PostalCode = _postalcode, + Country = _country, + StateOrRegion = _state, + City = _city, + IsActive = _isactive + }; + } + } } return null; } - public async Task GetResumeExperienceBullets(DbDataReader reader) { - List experienceBullets = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - int _experienceid = reader.GetInt32("ResumeExperienceID"); - string _jobfunction = reader.GetString("JobFunction"); - experienceBullets.Add(new ResumeExperienceBullet() { - ID = _id, - ResumeID = _resumeid, - ResumeExperienceID = _experienceid, - JobFunction = _jobfunction - }); - } - return experienceBullets.ToArray(); - } - - public async Task GetResumeExperience(DbDataReader reader) { + public async Task GetResumeExperience(int resumeId) { List experience = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _jobtitle = reader.GetString("JobTitle"); - string _company = reader.GetString("Company"); - string _postalcode = reader.GetString("PostalCode"); - string _country = reader.GetString("Country"); - string _state = reader.GetString("StateOrRegion"); - string _city = reader.GetString("City"); - DateTime _datestarted = reader.GetDateTime("DateStarted"); - bool _stillempoyed = reader.GetBoolean("StillEmployed"); - DateTime _dateended = reader.GetDateTime("DateEnded"); - experience.Add(new ResumeExperience() { - ID = _id, - ResumeID = _resumeid, - JobTitle = _jobtitle, - Company = _company, - PostalCode = _postalcode, - Country = _country, - StateOrRegion = _state, - City = _city, - DateStarted = _datestarted, - StillEmployed = _stillempoyed, - DateEnded = _dateended, - }); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeExperience WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _jobtitle = GetString(reader, "JobTitle"); + string _company = GetString(reader, "Company"); + string _postalcode = GetString(reader, "PostalCode"); + string _country = GetString(reader, "Country"); + string _state = GetString(reader, "StateOrRegion"); + string _city = GetString(reader, "City"); + DateTime _datestarted = reader.GetDateTime("DateStarted"); + bool _stillempoyed = reader.GetBoolean("StillEmployed"); + DateTime _dateended = reader.GetDateTime("DateEnded"); + experience.Add(new ResumeExperience() { + ID = _id, + ResumeID = _resumeid, + JobTitle = _jobtitle, + Company = _company, + PostalCode = _postalcode, + Country = _country, + StateOrRegion = _state, + City = _city, + DateStarted = _datestarted, + StillEmployed = _stillempoyed, + DateEnded = _dateended, + }); + } + } } return experience.ToArray(); } - public async Task GetResumeMilitaryBullets(DbDataReader reader) { + public async Task GetResumeExperienceBullets(int resumeId) { + List experienceBullets = new List(); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeExperienceBullet WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + int _experienceid = reader.GetInt32("ResumeExperienceID"); + string _jobfunction = GetString(reader, "JobFunction"); + experienceBullets.Add(new ResumeExperienceBullet() { + ID = _id, + ResumeID = _resumeid, + ResumeExperienceID = _experienceid, + JobFunction = _jobfunction + }); + } + } + } + return experienceBullets.ToArray(); + } + + public async Task GetResumeMilitaryBullets(int resumeId) { List militaryBullets = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - int _experienceid = reader.GetInt32("ResumeMilitaryID"); - string _achievement = reader.GetString("Achievement"); - string _description = reader.GetString("Description"); - militaryBullets.Add(new ResumeMilitaryBullet() { - ID = _id, - ResumeID = _resumeid, - ResumeMilitaryID = _experienceid, - Achievement = _achievement, - Description = _description - }); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeMilitaryBullet WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + int _experienceid = reader.GetInt32("ResumeMilitaryID"); + string _achievement = GetString(reader, "Achievement"); + string _description = GetString(reader, "Description"); + militaryBullets.Add(new ResumeMilitaryBullet() { + ID = _id, + ResumeID = _resumeid, + ResumeMilitaryID = _experienceid, + Achievement = _achievement, + Description = _description + }); + } + } } return militaryBullets.ToArray(); } - public async Task GetResumeMilitary(DbDataReader reader) { + public async Task GetResumeMilitary(int resumeId) { ResumeMilitary? military = null; - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _country = reader.GetString("Country"); - string _rank = reader.GetString("Rank"); - DateTime _datestarted = reader.GetDateTime("DateStarted"); - bool _stillServing = reader.GetBoolean("StillServing"); - DateTime _dateended = reader.GetDateTime("DateEnded"); - military = new ResumeMilitary() { - ID = _id, - ResumeID = _resumeid, - Country = _country, - Rank = _rank, - DateStarted = _datestarted, - StillServing = _stillServing, - DateEnded = _dateended, - }; + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeMilitary WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _country = GetString(reader, "Country"); + string _rank = GetString(reader, "Rank"); + DateTime _datestarted = reader.GetDateTime("DateStarted"); + bool _stillServing = reader.GetBoolean("StillServing"); + DateTime _dateended = reader.GetDateTime("DateEnded"); + military = new ResumeMilitary() { + ID = _id, + ResumeID = _resumeid, + Country = _country, + Rank = _rank, + DateStarted = _datestarted, + StillServing = _stillServing, + DateEnded = _dateended, + }; + } + } } return military; } - public async Task GetResumeEducation(DbDataReader reader) { + public async Task GetResumeEducation(int resumeId) { List? education = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _degreetype = reader.GetString("DegreeType"); - string _degreefield = reader.GetString("DegreeField"); - string _school = reader.GetString("School"); - string _postalcode = reader.GetString("PostalCode"); - string _country = reader.GetString("Country"); - string _state = reader.GetString("StateOrRegion"); - string _city = reader.GetString("City"); - DateTime _datestarted = reader.GetDateTime("DateStarted"); - bool _stillstudying = reader.GetBoolean("StillStudying"); - DateTime _dateended = reader.GetDateTime("DateEnded"); - education.Add(new ResumeEducation { - ID = _id, - ResumeID = _resumeid, - DegreeType = _degreetype, - DegreeField = _degreefield, - School = _school, - PostalCode = _postalcode, - Country = _country, - StateOrRegion = _state, - City = _city, - DateStarted = _datestarted, - StillStudying = _stillstudying, - DateEnded = _dateended - }); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeEducation WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _degreetype = GetString(reader, "DegreeType"); + string _degreefield = GetString(reader, "DegreeField"); + string _school = GetString(reader, "School"); + string _postalcode = GetString(reader, "PostalCode"); + string _country = GetString(reader, "Country"); + string _state = GetString(reader, "StateOrRegion"); + string _city = GetString(reader, "City"); + DateTime _datestarted = reader.GetDateTime("DateStarted"); + bool _stillstudying = reader.GetBoolean("StillStudying"); + DateTime _dateended = reader.GetDateTime("DateEnded"); + education.Add(new ResumeEducation { + ID = _id, + ResumeID = _resumeid, + DegreeType = _degreetype, + DegreeField = _degreefield, + School = _school, + PostalCode = _postalcode, + Country = _country, + StateOrRegion = _state, + City = _city, + DateStarted = _datestarted, + StillStudying = _stillstudying, + DateEnded = _dateended + }); + } + } } return education.ToArray(); } - public async Task GetResumeSkills(DbDataReader reader) { + public async Task GetResumeSkills(int resumeId) { List skills = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _name = reader.GetString("Name"); - string _description = reader.GetString("Description"); - skills.Add( new ResumeSkill { - ID = _id, - ResumeID = _resumeid, - Name = _name, - Description = _description - } ); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeSkill WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _name = GetString(reader, "Name"); + string _description = GetString(reader, "Description"); + skills.Add(new ResumeSkill { + ID = _id, + ResumeID = _resumeid, + Name = _name, + Description = _description + }); + } + } } return skills.ToArray(); } - public async Task GetResumeLanguages(DbDataReader reader) { + public async Task GetResumeLanguages(int resumeId) { List? languages = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _language = reader.GetString("Language"); - string _proficiency = reader.GetString("Proficiency"); - languages.Add( new ResumeLanguage { - ID = _id, - ResumeID = _resumeid, - Language = _language, - Proficiency = _proficiency - } ); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeLanguage WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _language = GetString(reader, "Language"); + string _proficiency = GetString(reader, "Proficiency"); + languages.Add(new ResumeLanguage { + ID = _id, + ResumeID = _resumeid, + Language = _language, + Proficiency = _proficiency + }); + } + } } return languages.ToArray(); } - public async Task GetResumeCertification(DbDataReader reader) { + public async Task GetResumeCertification(int resumeId) { List certs = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _name = reader.GetString("Name"); - string _url = reader.GetString("VerificationURL"); - string _description = reader.GetString("Description"); - certs.Add( new ResumeCertification { - ID = _id, - ResumeID = _resumeid, - Name = _name, - VerificationURL = _url, - Description = _description - } ); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeCertification WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _name = GetString(reader, "Name"); + string _url = GetString(reader, "VerificationURL"); + string _description = GetString(reader, "Description"); + certs.Add(new ResumeCertification { + ID = _id, + ResumeID = _resumeid, + Name = _name, + VerificationURL = _url, + Description = _description + }); + } + } } return certs.ToArray(); } - public async Task GetResumeProjects(DbDataReader reader) { + public async Task GetResumeProjects(int resumeId) { List? projects = new List(); - while (await reader.ReadAsync()) { - if (reader == null) { break; } - int _id = reader.GetInt32("ID"); - int _resumeid = reader.GetInt32("ResumeID"); - string _name = reader.GetString("Name"); - string _url = reader.GetString("URL"); - string _description = reader.GetString("Description"); - projects.Add( new ResumeProject { - ID = _id, - ResumeID = _resumeid, - Name = _name, - URL = _url, - Description = _description - } ); + using (var conn = GetConnection()) { + await conn.OpenAsync(); + var cmd = new MySqlCommand("SELECT * FROM ResumeProject WHERE ResumeID = @ResumeID;", conn); + cmd.Parameters.AddWithValue("@ResumeID", resumeId); + using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { + while (await reader.ReadAsync()) { + int _id = reader.GetInt32("ID"); + int _resumeid = reader.GetInt32("ResumeID"); + string _name = GetString(reader, "Name"); + string _url = GetString(reader, "URL"); + string _description = GetString(reader, "Description"); + projects.Add(new ResumeProject { + ID = _id, + ResumeID = _resumeid, + Name = _name, + URL = _url, + Description = _description + }); + } + } } return projects.ToArray(); } - } } -- 2.52.0