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 GetResumes(int AccountID) { List resumes = new List(); using (MySqlConnection connection = GetConnection()) { connection.Open(); string command = @" SELECT * FROM Resume WHERE AccountID = @AccountID; "; MySqlCommand cmd = new MySqlCommand(command, connection); cmd.Parameters.AddWithValue("@AccountID", AccountID); using (DbDataReader reader = await cmd.ExecuteReaderAsync()) { 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"); resumes.Add( new Resume() { ID = _id, AccountID = _accountid, Name = _name, Field = _field, Email = _email, PhoneNumber = _phonenumber, PostalCode = _postalcode, Country = _country, StateOrRegion = _state, City = _city, IsActive = _isactive } ); } } } return resumes.ToArray(); } 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); 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 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(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 }; } } using (DbDataReader reader = await ResumeExperienceReader) { } using (DbDataReader reader = await ResumeExperienceBulletReader) { } using (DbDataReader reader = await ResumeMilitaryReader) { } using (DbDataReader reader = await ResumeMilitaryBulletReader) { } using (DbDataReader reader = await ResumeEducationReader) { } using (DbDataReader reader = await ResumeSkillReader) { } using (DbDataReader reader = await ResumeLanguageReader) { } using (DbDataReader reader = await ResumeCertificationReader) { } using (DbDataReader reader = await ResumeProjectnReader) { } } return resume; } public async Task SetResume( Resume resume ) { using( MySqlConnection connection = GetConnection() ) { connection.Open(); string command = @" INSERT INTO Account (ID,UserName,Email,EmailVerified,PasswordHash,FailedPasswordLock,PasswordAttempts,CurrentPasswordAttempts,Role,EmailToken,DataServer) VALUES (@ID,@UserName,@Email,@EmailVerified,@PasswordHash,@FailedPasswordLock,@PasswordAttempts,@CurrentPasswordAttempts,@Role,@EmailToken,@DataServer); ON DUPLICATE KEY UPDATE UserName = @UserName, Email = @Email, EmailVerified = @EmailVerified, PasswordHash = @PasswordHash, FailedPasswordLock = @FailedPasswordLock, PasswordAttempts = @PasswordAttempts, CurrentPasswordAttempts = @CurrentPasswordAttempts, Role = @Role, EmailToken = @EmailToken; DataServer = @DataServer; "; MySqlCommand cmd = new MySqlCommand( command , connection); cmd.Parameters.AddWithValue("@ID", Profile.ID); cmd.Parameters.AddWithValue("@UserName", Profile.UserName); cmd.Parameters.AddWithValue("@Email", Profile.Email); cmd.Parameters.AddWithValue("@EmailVerified", Profile.EmailVerified); cmd.Parameters.AddWithValue("@PasswordHash", Profile.PasswordHash); cmd.Parameters.AddWithValue("@FailedPasswordLock", Profile.FailedPasswordLock); cmd.Parameters.AddWithValue("@PasswordAttempts", Profile.PasswordAttempts); cmd.Parameters.AddWithValue("@CurrentPasswordAttempts", Profile.CurrentPasswordAttempts); cmd.Parameters.AddWithValue("@Role", Profile.Role); cmd.Parameters.AddWithValue("@EmailToken", Profile.EmailToken); cmd.Parameters.AddWithValue("@DataServer", Profile.DataServer); await cmd.ExecuteNonQueryAsync(); } } public async Task DeleteResume( int ID ) { using( MySqlConnection connection = GetConnection() ) { MySqlCommand cmd; connection.Open(); string command = @" DELETE FROM Resume WHERE ID = @ID; "; cmd = new MySqlCommand( command, connection ); cmd.Parameters.AddWithValue("@ID", ID); await cmd.ExecuteNonQueryAsync(); } } } }