Update Account DbService
Docker Build and Release Upload / build (push) Failing after 58s

This commit is contained in:
2025-07-13 20:25:33 -07:00
parent ddf78e5606
commit 00f245ccef
7 changed files with 8 additions and 607 deletions
-1
View File
@@ -11,6 +11,5 @@ namespace BoredCareers.Entities {
public string Role { get; set; } = "Generic"; public string Role { get; set; } = "Generic";
public string EmailToken { get; set; } = ""; public string EmailToken { get; set; } = "";
public string DataServer { get; set; } = ""; public string DataServer { get; set; } = "";
public string Error { get; set; } = "";
} }
} }
@@ -35,6 +35,7 @@ namespace BoredCareers.Services.DatabaseService {
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" ); int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
string _role = reader.GetString( "Role" ); string _role = reader.GetString( "Role" );
string _emailtoken = reader.GetString( "EmailToken" ); string _emailtoken = reader.GetString( "EmailToken" );
string _dataserver = reader.GetString( "DataServer" );
account = new Account() { account = new Account() {
ID = _id, ID = _id,
@@ -47,6 +48,7 @@ namespace BoredCareers.Services.DatabaseService {
EmailToken = _emailtoken, EmailToken = _emailtoken,
FailedPasswordLock = _failedpasswordlock, FailedPasswordLock = _failedpasswordlock,
Role = _role, Role = _role,
DataServer = _dataserver
}; };
} }
} }
@@ -82,6 +84,7 @@ namespace BoredCareers.Services.DatabaseService {
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" ); int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
string _role = reader.GetString( "Role" ); string _role = reader.GetString( "Role" );
string _emailtoken = reader.GetString( "EmailToken" ); string _emailtoken = reader.GetString( "EmailToken" );
string _dataserver = reader.GetString("DataServer");
account = new Account() { account = new Account() {
ID = _id, ID = _id,
@@ -94,6 +97,7 @@ namespace BoredCareers.Services.DatabaseService {
EmailToken = _emailtoken, EmailToken = _emailtoken,
FailedPasswordLock = _failedpasswordlock, FailedPasswordLock = _failedpasswordlock,
Role = _role, Role = _role,
DataServer = _dataserver
}; };
} }
} }
@@ -107,9 +111,9 @@ namespace BoredCareers.Services.DatabaseService {
string command = @" string command = @"
INSERT INTO Account INSERT INTO Account
(ID,UserName,Email,EmailVerified,PasswordHash,FailedPasswordLock,PasswordAttempts,CurrentPasswordAttempts,Role,EmailToken) (ID,UserName,Email,EmailVerified,PasswordHash,FailedPasswordLock,PasswordAttempts,CurrentPasswordAttempts,Role,EmailToken,DataServer)
VALUES VALUES
(@ID,@UserName,@Email,@EmailVerified,@PasswordHash,@FailedPasswordLock,@PasswordAttempts,@CurrentPasswordAttempts,@Role,@EmailToken); (@ID,@UserName,@Email,@EmailVerified,@PasswordHash,@FailedPasswordLock,@PasswordAttempts,@CurrentPasswordAttempts,@Role,@EmailToken,@DataServer);
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE
UserName = @UserName, UserName = @UserName,
Email = @Email, Email = @Email,
@@ -120,6 +124,7 @@ namespace BoredCareers.Services.DatabaseService {
CurrentPasswordAttempts = @CurrentPasswordAttempts, CurrentPasswordAttempts = @CurrentPasswordAttempts,
Role = @Role, Role = @Role,
EmailToken = @EmailToken; EmailToken = @EmailToken;
DataServer = @DataServer;
"; ";
MySqlCommand cmd = new MySqlCommand( command , connection); MySqlCommand cmd = new MySqlCommand( command , connection);
@@ -133,6 +138,7 @@ namespace BoredCareers.Services.DatabaseService {
cmd.Parameters.AddWithValue("@CurrentPasswordAttempts", Profile.CurrentPasswordAttempts); cmd.Parameters.AddWithValue("@CurrentPasswordAttempts", Profile.CurrentPasswordAttempts);
cmd.Parameters.AddWithValue("@Role", Profile.Role); cmd.Parameters.AddWithValue("@Role", Profile.Role);
cmd.Parameters.AddWithValue("@EmailToken", Profile.EmailToken); cmd.Parameters.AddWithValue("@EmailToken", Profile.EmailToken);
cmd.Parameters.AddWithValue("@DataServer", Profile.DataServer);
await cmd.ExecuteNonQueryAsync(); await cmd.ExecuteNonQueryAsync();
} }
@@ -145,9 +151,6 @@ namespace BoredCareers.Services.DatabaseService {
string command = @" string command = @"
DELETE FROM Account WHERE ID = @ID; DELETE FROM Account WHERE ID = @ID;
DELETE FROM AccountInventory WHERE AccountID = @ID;
DELETE FROM ProjectMistData WHERE AccountID = @ID;
DELETE FROM Cart WHERE AccountID = @ID;
"; ";
cmd = new MySqlCommand( command, connection ); cmd = new MySqlCommand( command, connection );
cmd.Parameters.AddWithValue("@ID", ID); cmd.Parameters.AddWithValue("@ID", ID);
@@ -1,82 +0,0 @@
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<Cart[]> GetCart( int accountID ) {
List<Cart> list = new List<Cart>();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROM Cart
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 _productid = reader.GetInt32("ProductID");
list.Add( new Cart() {
ID = _id,
AccountID = _accountid,
ProductID = _productid
} );
}
}
}
return list.ToArray();
}
public async Task AddToCart( Cart item ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
INSERT INTO Cart
(AccountID, ProductID)
VALUES
(@AccountID, @ProductID);
";
MySqlCommand cmd = new MySqlCommand( command , connection);
cmd.Parameters.AddWithValue("@AccountID", item.AccountID);
cmd.Parameters.AddWithValue("@ProductID", item.ProductID);
await cmd.ExecuteNonQueryAsync();
}
}
public async Task RemoveFromCart( Cart item ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = "DELETE FROM Cart WHERE AccountID=" + item.AccountID + " AND ProductID=" + item.ProductID + ";";
MySqlCommand cmd = new MySqlCommand( command , connection);
await cmd.ExecuteNonQueryAsync();
}
}
public async Task ClearCart( int accountID ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
DELETE FROM Cart
WHERE AccountID = @AccountID;
";
MySqlCommand cmd = new MySqlCommand( command , connection);
cmd.Parameters.AddWithValue("@AccountID", accountID);
await cmd.ExecuteNonQueryAsync();
}
}
}
}
@@ -1,136 +0,0 @@
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<Product?> GetProduct(int ID) {
Product? items = null;
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
SELECT * FROM Product
WHERE ID = @ID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", ID);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
int _id = reader.GetInt32("ID");
string _name = reader.GetString("Name");
string _description = reader.GetString("Description");
int _cost = reader.GetInt32("Cost");
string _url = reader.GetString("URL");
ProductImage[] images = await GetAllImages(_id);
items = new Product() {
ID = _id,
Name = _name,
Images = images,
Description = _description,
Cost = _cost,
URL = _url
};
}
}
}
return items;
}
public async Task<Product[]> GetAllProducts() {
List<Product> items = new List<Product>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
MySqlCommand cmd = new MySqlCommand("SELECT * FROM Product", connection);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
int _id = reader.GetInt32("ID");
string _name = reader.GetString("Name");
string _description = reader.GetString("Description");
int _cost = reader.GetInt32("Cost");
string _url = reader.GetString("URL");
ProductImage[] images = await GetAllImages(_id);
items.Add(new Product() {
ID = _id,
Name = _name,
Images = images,
Description = _description,
Cost = _cost,
URL = _url
});
}
}
}
return items.ToArray();
}
public async Task SetProduct(Product Item) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
INSERT INTO Product
(ID,Name,Description,Cost,URL)
VALUES
(@ID,@Name,@Description,@Cost,@URL)
ON DUPLICATE KEY UPDATE
Name = @Name,
Description = @Description,
Cost = @Cost,
URL = @URL
WHERE ID = @ID;
SELECT ID FROM Product
WHERE Name = @Name;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", Item.ID);
cmd.Parameters.AddWithValue("@Name", Item.Name);
cmd.Parameters.AddWithValue("@Description", Item.Description);
cmd.Parameters.AddWithValue("@Cost", Item.Cost);
cmd.Parameters.AddWithValue("@URL", Item.URL);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
Item.ID = reader.GetInt32("ID");
}
}
await AddAllImages(Item);
}
}
public async Task DeleteProduct(int ID) {
using (MySqlConnection connection = GetConnection()) {
await DeleteAllImages(ID);
connection.Open();
string command = @"
DELETE FROM Product
WHERE ID = @ID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ID", ID);
await cmd.ExecuteNonQueryAsync();
}
}
}
}
@@ -1,112 +0,0 @@
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<ProductImage?> GetImage(int ProductID, int ImageID) {
ProductImage? item = null;
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
SELECT * FROM ProductImage
WHERE ProductID = @ProductID AND ImageID = @ImageID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ProductID", ProductID);
cmd.Parameters.AddWithValue("@ImageID", ImageID);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
int _ImageID = reader.GetInt32("ImageID");
int _ProductID = reader.GetInt32("ProductID");
byte[] _Image = (byte[])reader["Image"];
string _Name = reader.GetString("Name");
item = new ProductImage() {
ImageID = _ImageID,
ProductID = _ProductID,
Image = _Image,
Name = _Name
};
break;
}
}
}
return item;
}
public async Task<ProductImage[]> GetAllImages(int ProductID) {
List<ProductImage> items = new List<ProductImage>();
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
SELECT * FROM ProductImage
WHERE ProductID = @ProductID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ProductID", ProductID);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
int _ImageID = reader.GetInt32("ImageID");
int _ProductID = reader.GetInt32("ProductID");
string _Name = reader.GetString("Name");
items.Add(new ProductImage() {
ImageID = _ImageID,
ProductID = _ProductID,
Name = _Name
});
}
}
}
return items.ToArray();
}
public async Task AddAllImages(Product Item) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
foreach (ProductImage cur in Item.Images) {
if (cur.Image != null) {
string command = @"
INSERT INTO ProductImage
(ProductID, Image, Name)
VALUES
(@ProductID, @Image, @Name);
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ProductID", Item.ID);
cmd.Parameters.AddWithValue("@Image", cur.Image );
cmd.Parameters.AddWithValue("@Name", cur.Name );
await cmd.ExecuteNonQueryAsync();
}
}
}
}
public async Task DeleteAllImages(int ItemID) {
using (MySqlConnection connection = GetConnection()) {
connection.Open();
string command = @"
DELETE FROM ProductImage
WHERE ProductID = @ProductID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@ProductID", ItemID);
await cmd.ExecuteNonQueryAsync();
}
}
}
}
@@ -1,100 +0,0 @@
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<ProductInventory[]> GetAllProductInventory( int accountID, int productID ) {
List<ProductInventory> list = new List<ProductInventory>();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROM ProductInventory
WHERE AccountID = @AccountID AND ProductID = @ProductID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@AccountID", accountID);
cmd.Parameters.AddWithValue("@ProductID", productID);
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
while( await reader.ReadAsync() ) {
if( reader == null ) {
break;
}
string _Key = reader.GetString("Key");
string _Value = reader.GetString("Value");
list.Add( new ProductInventory() {
AccountID = accountID,
ProductID = productID,
Key = _Key,
Value = _Value
} );
}
}
}
return list.ToArray();
}
public async Task<ProductInventory> GetProductInventory( int accountID, int productID, string Key ) {
ProductInventory item = new ProductInventory();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROM ProductInventory
WHERE AccountID = @AccountID AND ProductID = @ProductID AND Key = @Key;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@AccountID", accountID);
cmd.Parameters.AddWithValue("@ProductID", productID);
cmd.Parameters.AddWithValue("@Key", Key);
using (DbDataReader reader = await cmd.ExecuteReaderAsync()) {
while (await reader.ReadAsync()) {
if (reader == null) {
break;
}
string _Key = reader.GetString("Key");
string _Value = reader.GetString("Value");
item = new ProductInventory() {
AccountID = accountID,
ProductID = productID,
Key = _Key,
Value = _Value
};
}
}
}
return item;
}
async Task SetProductInventory(ProductInventory item) {
using (MySqlConnection connection = GetConnection()) {
string command = @"
INSERT INTO ProductInventory
(AccountID, ProductID, `Key`, `Value`)
Values
(@AccountID, @ProductID, @Key, @Value)
ON DUPLICATE KEY UPDATE
`Value` = @Value;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@AccountID", item.AccountID);
cmd.Parameters.AddWithValue("@ProductID", item.ProductID);
cmd.Parameters.AddWithValue("@Key", item.Key);
cmd.Parameters.AddWithValue("@Value", item.Value ?? (object)DBNull.Value);
await cmd.ExecuteNonQueryAsync();
}
}
}
}
@@ -1,171 +0,0 @@
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<Receipt[]> GetAllReceipts( int accountID ) {
List<Receipt> receipts = new List<Receipt> ();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROM Receipt
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 _accountid = reader.GetInt32("AccountID");
int _gameid = reader.GetInt32("ProductID");
string _receiptid = reader.GetString("ReceiptID");
int _lineitem = reader.GetInt32("LineItem");
DateTime _receiptdate = reader.GetDateTime("Time");
int _taxamount = reader.GetInt32("TaxAmount");
int _totalcost = reader.GetInt32("TotalCost");
receipts.Add( new Receipt() {
AccountID = _accountid,
ProductID = _gameid,
ReceiptID = _receiptid,
Time = _receiptdate,
TotalCost = _totalcost,
TaxAmount = _taxamount,
LineItem = _lineitem
} );
}
}
}
return receipts.ToArray();
}
public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( int accountID ) {
List<( Receipt, Product )> join = new();
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROM Receipt
LEFT JOIN Product
ON Receipt.ProductID = Product.ID
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 _accountid = !reader.IsDBNull( "AccountID" ) ? reader.GetInt32("AccountID") : -1;
int _gameid = !reader.IsDBNull( "ProductID" ) ? reader.GetInt32("ProductID") : 0;
string _receiptid = !reader.IsDBNull( "ReceiptID" ) ? reader.GetString("ReceiptID") : "";
int _lineitem = !reader.IsDBNull( "LineItem" ) ? reader.GetInt32("LineItem") : 0;
DateTime _receiptdate = !reader.IsDBNull( "Time" ) ? reader.GetDateTime("Time") : DateTime.Now;
int _taxamount = !reader.IsDBNull( "TaxAmount" ) ? reader.GetInt32("TaxAmount") : 0;
int _totalcost = !reader.IsDBNull( "TotalCost" ) ? reader.GetInt32("TotalCost") : 0;
int _id = !reader.IsDBNull( "ID" ) ? reader.GetInt32("ID") : 0;
string _name = !reader.IsDBNull( "Name" ) ? reader.GetString("Name") : "";
string _desc = !reader.IsDBNull( "Description" ) ? reader.GetString("Description") : "";
int _cost = !reader.IsDBNull( "Cost" ) ? reader.GetInt32("Cost") : 0;
string _url = !reader.IsDBNull( "URL" ) ? reader.GetString("URL") : "Something Random That Wont Ever Be In A URL";
Receipt r = new() {
AccountID = _accountid,
ProductID = _gameid,
ReceiptID = _receiptid,
Time = _receiptdate,
TotalCost = _totalcost,
TaxAmount = _taxamount,
LineItem = _lineitem
};
Product p = new() {
ID = _id,
Cost = _cost,
Description = _desc,
Name = _name,
URL = _url
};
join.Add( (r, p) );
}
}
}
return join.ToArray();
}
public async Task<Receipt?> GetReceipt( int accountID, int gameID ) {
Receipt? receipt = null;
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
SELECT * FROMReceipt
WHERE AccountID = @AccountID AND ProductID = @ProductID;
";
MySqlCommand cmd = new MySqlCommand(command, connection);
cmd.Parameters.AddWithValue("@AccountID", accountID);
cmd.Parameters.AddWithValue("@ProductID", gameID);
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
while( await reader.ReadAsync() ) {
if( reader == null ) {
break;
}
int _accountid = reader.GetInt32("AccountID");
int _gameid = reader.GetInt32("ProductID");
string _receiptid = reader.GetString("ReceiptID");
int _lineitem = reader.GetInt32("LineItem");
DateTime _receiptdate = reader.GetDateTime("Time");
int _taxamount = reader.GetInt32("TaxAmount");
int _totalcost = reader.GetInt32("TotalCost");
receipt = new Receipt() {
AccountID = _accountid,
ProductID = _gameid,
ReceiptID = _receiptid,
Time = _receiptdate,
TotalCost = _totalcost,
TaxAmount = _taxamount,
LineItem = _lineitem
};
}
}
}
return receipt;
}
public async Task NewReceipt( Receipt receipt ) {
using( MySqlConnection connection = GetConnection() ) {
connection.Open();
string command = @"
INSERT INTO Receipt
(AccountID, ProductID, ReceiptID, LineItem, TaxAmount, TotalCost, Time)
VALUES
(@AccountID, @ProductID, @ReceiptID, @LineItem, @TaxAmount, @TotalCost, @Time)
";
MySqlCommand cmd = new MySqlCommand( command , connection);
cmd.Parameters.AddWithValue("@AccountID", receipt.AccountID);
cmd.Parameters.AddWithValue("@ProductID", receipt.ProductID);
cmd.Parameters.AddWithValue("@ReceiptID", receipt.ReceiptID);
cmd.Parameters.AddWithValue("@LineItem", receipt.LineItem);
cmd.Parameters.AddWithValue("@TaxAmount", receipt.TaxAmount);
cmd.Parameters.AddWithValue("@TotalCost", receipt.TotalCost);
cmd.Parameters.AddWithValue("@Time", receipt.Time); // Just incase i need this in the future | receipt.Time.ToString( "yyyy-MM-dd hh:mm:ss" )
await cmd.ExecuteNonQueryAsync();
}
}
}
}