diff --git a/src/Server/Services/DatabaseService/Resume.cs b/src/Server/Services/DatabaseService/Resume.cs index f10c787..3429f1b 100644 --- a/src/Server/Services/DatabaseService/Resume.cs +++ b/src/Server/Services/DatabaseService/Resume.cs @@ -58,113 +58,179 @@ namespace BoredCareers.Services.DatabaseService { public async Task GetResume(int ResumeID) { Resume? resume = null; - using (MySqlConnection connection = GetConnection()) { - connection.Open(); - MySqlCommand resumeCommand = new MySqlCommand("SELECT * FROM Resume WHERE ID = @ResumeID;", connection); - MySqlCommand ResumeExperienceCommand = new MySqlCommand("SELECT * FROM ResumeExperience WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeExperienceBulletCommand = new MySqlCommand("SELECT * FROM ResumeExperienceBullet WHERE ResumeID = @ResumeID;"); - MySqlCommand ResumeMilitaryCommand = new MySqlCommand("SELECT * FROM ResumeMilitary WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeMilitaryBulletCommand = new MySqlCommand("SELECT * FROM ResumeMilitaryBullet WHERE ResumeID = @ResumeID", connection); - MySqlCommand ResumeEducationCommand = new MySqlCommand("SELECT * FROM ResumeEducation WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeSkillCommand = new MySqlCommand("SELECT * FROM ResumeSkill WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeLanguageCommand = new MySqlCommand("SELECT * FROM ResumeLanguage WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeCertificationCommand = new MySqlCommand("SELECT * FROM ResumeCertification WHERE ResumeID = @ResumeID;", connection); - MySqlCommand ResumeProjectCommand = new MySqlCommand("SELECT * FROM ResumeProject WHERE ResumeID = @ResumeID;", connection); + 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(); - 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); + 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 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 ResumeProjectnReader = ResumeProjectCommand.ExecuteReaderAsync(); + await Task.WhenAll(resumeopen, resumeexperienceopen, resumeexperiencebulletopen, resumemilitaryopen, resumemilitarybulletopen, + resumeeducationopen, resumeskillopen, resumelanguageopen, resumecertifcationopen, resumeprojectopen); - await Task.WhenAll(resumeReader, ResumeExperienceReader, ResumeExperienceBulletReader, ResumeMilitaryReader, ResumeMilitaryBulletReader, ResumeEducationReader, ResumeSkillReader, ResumeLanguageReader, ResumeCertificationReader, ResumeProjectnReader); + 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); - using (DbDataReader reader = await resumeReader) { - while (await reader.ReadAsync()) { - if (reader == null) { - break; - } + 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); - int _id = reader.GetInt32("ID"); - int _accountid = reader.GetInt32("AccountID"); - 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"); + 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 ResumeProjectnReader = ResumeProjectCommand.ExecuteReaderAsync(); - resume = new Resume() { - ID = _id, - AccountID = _accountid, - Name = _name, - Field = _field, - Email = _email, - PhoneNumber = _phonenumber, - PostalCode = _postalcode, - Country = _country, - StateOrRegion = _state, - City = _city, - IsActive = _isactive - }; + await Task.WhenAll(resumeReader, ResumeExperienceReader, ResumeExperienceBulletReader, ResumeMilitaryReader, ResumeMilitaryBulletReader, + ResumeEducationReader, ResumeSkillReader, ResumeLanguageReader, ResumeCertificationReader, ResumeProjectnReader); + + using (DbDataReader reader = await resumeReader) { + while (await reader.ReadAsync()) { + if (reader == null) { break; } + int _id = reader.GetInt32("ID"); + int _accountid = reader.GetInt32("AccountID"); + 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"); + resume = new Resume() { + ID = _id, + AccountID = _accountid, + Name = _name, + Field = _field, + Email = _email, + PhoneNumber = _phonenumber, + PostalCode = _postalcode, + Country = _country, + StateOrRegion = _state, + City = _city, + IsActive = _isactive + }; + } + } + + List experienceBullets = new List(); + using (DbDataReader reader = await ResumeExperienceBulletReader) { + 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 + }); + } + } + Dictionary> groupedExperienceBullets = experienceBullets + .GroupBy(b => b.ResumeExperienceID) + .ToDictionary(g => g.Key, g => g.ToList()); + + using (DbDataReader reader = await ResumeExperienceReader) { + 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, + ExperienceBullets = groupedExperienceBullets[_id].ToArray() + } ); } + } - using (DbDataReader reader = await ResumeExperienceReader) { - - } + using (DbDataReader reader = await ResumeMilitaryBulletReader) { - using (DbDataReader reader = await ResumeExperienceBulletReader) { + } - } + using (DbDataReader reader = await ResumeMilitaryReader) { - using (DbDataReader reader = await ResumeMilitaryReader) { - - } + } - using (DbDataReader reader = await ResumeMilitaryBulletReader) { + using (DbDataReader reader = await ResumeEducationReader) { - } + } - using (DbDataReader reader = await ResumeEducationReader) { + using (DbDataReader reader = await ResumeSkillReader) { - } + } - using (DbDataReader reader = await ResumeSkillReader) { + using (DbDataReader reader = await ResumeLanguageReader) { - } + } - using (DbDataReader reader = await ResumeLanguageReader) { + using (DbDataReader reader = await ResumeCertificationReader) { - } + } - using (DbDataReader reader = await ResumeCertificationReader) { - - } - - using (DbDataReader reader = await ResumeProjectnReader) { - - } + using (DbDataReader reader = await ResumeProjectnReader) { + } return resume; }