Fix employee drivers
This commit is contained in:
@@ -6,8 +6,8 @@ using System.Data.Common;
|
||||
namespace BoredCareers.Services.DatabaseService {
|
||||
public partial class DatabaseService {
|
||||
|
||||
public async Task<Employee[]> GetEmployees( int CompanyID ) {
|
||||
List<Employee> employees = new List<Employee>();
|
||||
public async Task<Employee?> GetEmployee( int EmployeeID ) {
|
||||
Employee? employee = null;
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
connection.Open();
|
||||
string command = @"
|
||||
@@ -17,7 +17,7 @@ namespace BoredCareers.Services.DatabaseService {
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@ID", CompanyID);
|
||||
cmd.Parameters.AddWithValue("@ID", EmployeeID);
|
||||
|
||||
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
||||
while( await reader.ReadAsync() ) {
|
||||
@@ -26,6 +26,68 @@ namespace BoredCareers.Services.DatabaseService {
|
||||
int _accountid = reader.GetInt32("AccountID");
|
||||
int _companyid = reader.GetInt32("CompanyID");
|
||||
|
||||
employee = new Employee() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
CompanyID = _companyid
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
|
||||
public async Task<Employee[]> GetEmployeesFromCompany(int CompanyID) {
|
||||
List<Employee> employees = new List<Employee>();
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
connection.Open();
|
||||
string command = @"
|
||||
SELECT *
|
||||
FROM Employee
|
||||
WHERE CompanyID = @CompanyID;
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@CompanyID", CompanyID);
|
||||
|
||||
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
|
||||
while (await reader.ReadAsync()) {
|
||||
if (reader == null) { break; }
|
||||
int _id = reader.GetInt32("ID");
|
||||
int _accountid = reader.GetInt32("AccountID");
|
||||
int _companyid = reader.GetInt32("CompanyID");
|
||||
|
||||
employees.Add(new Employee() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
CompanyID = _companyid
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return employees.ToArray();
|
||||
}
|
||||
|
||||
public async Task<Employee[]> GetEmployeesFromAccount(int AccountID) {
|
||||
List<Employee> employees = new List<Employee>();
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
connection.Open();
|
||||
string command = @"
|
||||
SELECT *
|
||||
FROM Employee
|
||||
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");
|
||||
int _companyid = reader.GetInt32("CompanyID");
|
||||
|
||||
employees.Add(new Employee() {
|
||||
ID = _id,
|
||||
AccountID = _accountid,
|
||||
@@ -37,8 +99,8 @@ namespace BoredCareers.Services.DatabaseService {
|
||||
return employees.ToArray();
|
||||
}
|
||||
|
||||
public async Task SetEmployee( Employee employee ) {
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
public async Task SetEmployee(Employee employee) {
|
||||
using (MySqlConnection connection = GetConnection()) {
|
||||
connection.Open();
|
||||
|
||||
string command = @"
|
||||
@@ -51,7 +113,7 @@ namespace BoredCareers.Services.DatabaseService {
|
||||
CompanyID = @CompanyID;
|
||||
";
|
||||
|
||||
MySqlCommand cmd = new MySqlCommand( command , connection);
|
||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||
cmd.Parameters.AddWithValue("@ID", employee.ID);
|
||||
cmd.Parameters.AddWithValue("@AccountID", employee.AccountID);
|
||||
cmd.Parameters.AddWithValue("@CompanyID", employee.CompanyID);
|
||||
|
||||
Reference in New Issue
Block a user