diff --git a/src/MistoxWebsite.Server/Entities/SessionObjects.cs b/src/MistoxWebsite.Server/Entities/SessionObjects.cs deleted file mode 100644 index 516d27a..0000000 --- a/src/MistoxWebsite.Server/Entities/SessionObjects.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MistoxWebsite.Server.Entities { - - public class AccountClaims { - public string UserName { get; set; } = string.Empty; - public string Email { get; set; } = string.Empty; - public string EmailVerified { get; set; } = string.Empty; - public string Role { get; set; } = string.Empty; - public string FailedPasswordLock { get; set; } = string.Empty; - } - -} \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Entities/UserInventory.cs b/src/MistoxWebsite.Server/Entities/UserInventory.cs deleted file mode 100644 index d219683..0000000 --- a/src/MistoxWebsite.Server/Entities/UserInventory.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MistoxWebsite.Server.Entities { - - public class UserInventory { - public string Item { get; set; } = string.Empty; - public int Quantity { get; set; } - public string Stats { get; set; } = string.Empty; - } - -} \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/Account.cs b/src/MistoxWebsite.Server/Services/DatabaseService/Account.cs index 91b1d5a..617d5fa 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/Account.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/Account.cs @@ -13,8 +13,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService { string command = @" SELECT * FROM Account - Left Join WebsiteData - On Account.ID = WebsiteData.AccountID WHERE UserName = @UorE OR Email = @UorE; "; @@ -32,7 +30,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService { string _email = reader.GetString("Email"); bool _emailVerified = reader.GetBoolean("EmailVerified"); string _passwordhash = reader.GetString("PasswordHash"); - bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" ); int _passwordattempts = reader.GetInt32( "PasswordAttempts" ); int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" ); @@ -45,14 +42,11 @@ namespace MistoxWebsite.Server.Services.DatabaseService { Email = _email, EmailVerified = _emailVerified, PasswordHash = _passwordhash, - SiteData = new WebSiteData() { - AccountID = _id, - CurrentPasswordAttempts = _curpasswordattempts, - PasswordAttempts = _passwordattempts, - EmailToken = _emailtoken, - FailedPasswordLock = _failedpasswordlock, - Role = _role, - } + CurrentPasswordAttempts = _curpasswordattempts, + PasswordAttempts = _passwordattempts, + EmailToken = _emailtoken, + FailedPasswordLock = _failedpasswordlock, + Role = _role, }; } } @@ -60,15 +54,13 @@ namespace MistoxWebsite.Server.Services.DatabaseService { return account; } - public async Task GetAccountByID( int ID ) { + public async Task GetAccount( int ID ) { Account? account = null; using( MySqlConnection connection = GetConnection() ) { connection.Open(); string command = @" SELECT * FROM Account - Left Join WebsiteData - On Account.ID = WebsiteData.AccountID WHERE ID = @ID; "; @@ -85,7 +77,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService { string _email = reader.GetString("Email"); bool _emailVerified = reader.GetBoolean("EmailVerified"); string _passwordhash = reader.GetString("PasswordHash"); - bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" ); int _passwordattempts = reader.GetInt32( "PasswordAttempts" ); int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" ); @@ -98,14 +89,11 @@ namespace MistoxWebsite.Server.Services.DatabaseService { Email = _email, EmailVerified = _emailVerified, PasswordHash = _passwordhash, - SiteData = new WebSiteData() { - AccountID = _id, - CurrentPasswordAttempts = _passwordattempts, - PasswordAttempts = _passwordattempts, - EmailToken = _emailtoken, - FailedPasswordLock = _failedpasswordlock, - Role = _role, - } + CurrentPasswordAttempts = _passwordattempts, + PasswordAttempts = _passwordattempts, + EmailToken = _emailtoken, + FailedPasswordLock = _failedpasswordlock, + Role = _role, }; } } @@ -113,65 +101,44 @@ namespace MistoxWebsite.Server.Services.DatabaseService { return account; } - public async Task SetAccount( Account Update ) { + public async Task SetAccount( Account Profile ) { using( MySqlConnection connection = GetConnection() ) { connection.Open(); + string command = @" - UPDATE Account SET + INSERT INTO Account + (ID,UserName,Email,EmailVerified,PasswordHash,FailedPasswordLock,PasswordAttempts,CurrentPasswordAttempts,Role,EmailToken) + VALUES + (@ID,@UserName,@Email,@EmailVerified,@PasswordHash,@FailedPasswordLock,@PasswordAttempts,@CurrentPasswordAttempts,@Role,@EmailToken); + ON DUPLICATE KEY UPDATE UserName = @UserName, Email = @Email, EmailVerified = @EmailVerified, - PasswordHash = @PasswordHash - WHERE ID = @ID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@UserName", Update.UserName); - cmd.Parameters.AddWithValue("@Email", Update.Email); - cmd.Parameters.AddWithValue("@EmailVerified", Update.EmailVerified); - cmd.Parameters.AddWithValue("@PasswordHash", Update.PasswordHash); - cmd.Parameters.AddWithValue("@ID", Update.ID); - - await cmd.ExecuteNonQueryAsync(); - await UpdateWebsiteData( Update, Update.SiteData ); - } - } - - public async Task NewAccount( Account Profile ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - - int EmailVer = Profile.EmailVerified ? 1 : 0; - string command = @" - INSERT INTO Account - (UserName,Email,EmailVerified,PasswordHash) - VALUES - (@UserName,@Email,@EmailVerified,@PasswordHash); - - SELECT ID FROM Account - WHERE UserName = @UserName; + PasswordHash = @PasswordHash, + FailedPasswordLock = @FailedPasswordLock, + PasswordAttempts = @PasswordAttempts, + CurrentPasswordAttempts = @CurrentPasswordAttempts, + Role = @Role, + EmailToken = @EmailToken; "; 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); - using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { - while( await reader.ReadAsync() ) { - if( reader == null ) { - break; - } - int _id = reader.GetInt32("ID"); - Profile.ID = _id; - } - } - await NewWebsiteData( Profile, Profile.SiteData ); + await cmd.ExecuteNonQueryAsync(); } } - public async Task DeleteAccount( Account Profile ) { + public async Task DeleteAccount( int ID ) { using( MySqlConnection connection = GetConnection() ) { MySqlCommand cmd; connection.Open(); @@ -181,10 +148,9 @@ namespace MistoxWebsite.Server.Services.DatabaseService { DELETE FROM AccountInventory WHERE AccountID = @ID; DELETE FROM ProjectMistData WHERE AccountID = @ID; DELETE FROM Cart WHERE AccountID = @ID; - DELETE FROM WebsiteData WHERE AccountID = @ID; "; cmd = new MySqlCommand( command, connection ); - cmd.Parameters.AddWithValue("@ID", Profile.ID); + cmd.Parameters.AddWithValue("@ID", ID); await cmd.ExecuteNonQueryAsync(); } diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/AccountInventory.cs b/src/MistoxWebsite.Server/Services/DatabaseService/AccountInventory.cs deleted file mode 100755 index e2a99a3..0000000 --- a/src/MistoxWebsite.Server/Services/DatabaseService/AccountInventory.cs +++ /dev/null @@ -1,116 +0,0 @@ -using MistoxWebsite.Server.Entities; -using MySql.Data.MySqlClient; -using System.Data; -using System.Data.Common; - -// Account inventory needs to know whether there is already an object with the specified PK before making a new item -// If item exists already update the one that already exists - -namespace MistoxWebsite.Server.Services.DatabaseService { - public partial class DatabaseService { - - public async Task GetInventory( Account account, Product product ) { - List list = new List(); - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - SELECT * FROM AccountInventory - WHERE AccountID = @AccountID AND ProductID = @ProductID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); - cmd.Parameters.AddWithValue("@ProductID", product.ID); - - using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { - while( await reader.ReadAsync() ) { - if( reader == null ) { - break; - } - - string _item = reader.GetString("Item"); - int _quantity = reader.GetInt32("Quantity"); - string _stats = reader.GetString("Stats"); - - list.Add( new UserInventory() { - Item = _item, - Quantity = _quantity, - Stats = _stats - } ); - } - } - } - return list.ToArray(); - } - - async Task UpdateInventory( MySqlConnection connection, AccountInventory item ) { - string command = @" - UPDATE AccountInventory - SET AccountID = @AccountID, - ProductID = @ProductID, - Item = @Item, - Quantity = @Quantity, - Stats = @Stats - WHERE (AccountID = @AccountID AND ProductID = @ProductID AND Item = @Item); - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", item.AccountID); - cmd.Parameters.AddWithValue("@ProductID", item.ProductID); - cmd.Parameters.AddWithValue("@Item", item.Item); - cmd.Parameters.AddWithValue("@Quantity", item.Quantity); - cmd.Parameters.AddWithValue("@Stats", item.Stats); - - await cmd.ExecuteNonQueryAsync(); - } - - async Task NewInventory( MySqlConnection connection, AccountInventory item ) { - string command = @" - INSERT INTO AccountInventory (AccountID, ProductID, Item, Quantity, Stats) - VALUES - (@AccountID, @ProductID, @Item, @Quantity, @Stats); - "; - - MySqlCommand cmd = new MySqlCommand( command , connection); - cmd.Parameters.AddWithValue("@AccountID", item.AccountID); - cmd.Parameters.AddWithValue("@ProductID", item.ProductID); - cmd.Parameters.AddWithValue("@Item", item.Item); - cmd.Parameters.AddWithValue("@Quantity", item.Quantity); - cmd.Parameters.AddWithValue("@Stats", item.Stats); - - await cmd.ExecuteNonQueryAsync(); - } - - // Test to see if reader read does what its supposed to - // Not fully implimented - public async Task SetInventory( Account account, Product game, List Item ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - foreach( UserInventory item in Item ) { - bool exists = false; - MySqlCommand cmd = new MySqlCommand("SELECT * FROM AccountInventory WHERE AccountID = '" + account.ID + "' AND ProductID = '" + game.ID + "' AND Item = '" + item.Item.ToLower() + "'", connection); - using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { - exists = reader.HasRows; - } - if( exists ) { - await UpdateInventory( connection, new AccountInventory() { - AccountID = account.ID, - ProductID = game.ID, - Item = item.Item, - Quantity = item.Quantity, - Stats = item.Stats - } ); - } else { - await NewInventory( connection, new AccountInventory() { - AccountID = account.ID, - ProductID = game.ID, - Item = item.Item, - Quantity = item.Quantity, - Stats = item.Stats - } ); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/Cart.cs b/src/MistoxWebsite.Server/Services/DatabaseService/Cart.cs index ae2fcc1..7149471 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/Cart.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/Cart.cs @@ -6,7 +6,7 @@ using System.Data.Common; namespace MistoxWebsite.Server.Services.DatabaseService { public partial class DatabaseService { - public async Task GetCart( Account account ) { + public async Task GetCart( int accountID ) { List list = new List(); using( MySqlConnection connection = GetConnection() ) { connection.Open(); @@ -16,7 +16,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { "; MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); + cmd.Parameters.AddWithValue("@AccountID", accountID); using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { @@ -64,7 +64,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { } } - public async Task ClearCart( Account account ) { + public async Task ClearCart( int accountID ) { using( MySqlConnection connection = GetConnection() ) { connection.Open(); string command = @" @@ -73,7 +73,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { "; MySqlCommand cmd = new MySqlCommand( command , connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); + cmd.Parameters.AddWithValue("@AccountID", accountID); await cmd.ExecuteNonQueryAsync(); } diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs b/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs index d42a046..74bb018 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/Product.cs @@ -77,20 +77,27 @@ namespace MistoxWebsite.Server.Services.DatabaseService { return items.ToArray(); } - public async Task NewProduct(Product Item) { + public async Task SetProduct(Product Item) { using (MySqlConnection connection = GetConnection()) { connection.Open(); string command = @" INSERT INTO Product - (Name, Description, Cost, URL) + (ID,Name,Description,Cost,URL) VALUES - (@Name, @Description, @Cost, @URL); + (@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); @@ -109,36 +116,10 @@ namespace MistoxWebsite.Server.Services.DatabaseService { } } - public async Task UpdateProduct(Product Item) { - using (MySqlConnection connection = GetConnection()) { - connection.Open(); - - string command = @"UPDATE Product SET - Name = @Name, - Description = @Description, - Cost = @Cost, - URL = @URL - WHERE ID = @ID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@Name", Item.Name); - cmd.Parameters.AddWithValue("@Description", Item.Description); - cmd.Parameters.AddWithValue("@Cost", Item.Cost); - cmd.Parameters.AddWithValue("@URL", Item.URL); - cmd.Parameters.AddWithValue("@ID", Item.ID); - - await cmd.ExecuteNonQueryAsync(); - - await DeleteAllImages(Item.ID); - await AddAllImages(Item); - } - } - - public async Task DeleteProduct(int ProductID) { + public async Task DeleteProduct(int ID) { using (MySqlConnection connection = GetConnection()) { - await DeleteAllImages(ProductID); + await DeleteAllImages(ID); connection.Open(); string command = @" @@ -146,7 +127,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { WHERE ID = @ID; "; MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@ID", ProductID); + cmd.Parameters.AddWithValue("@ID", ID); await cmd.ExecuteNonQueryAsync(); } diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/ProductInventory.cs b/src/MistoxWebsite.Server/Services/DatabaseService/ProductInventory.cs new file mode 100755 index 0000000..7a0f496 --- /dev/null +++ b/src/MistoxWebsite.Server/Services/DatabaseService/ProductInventory.cs @@ -0,0 +1,100 @@ +using MistoxWebsite.Server.Entities; +using MySql.Data.MySqlClient; +using System.Data; +using System.Data.Common; + +namespace MistoxWebsite.Server.Services.DatabaseService { + public partial class DatabaseService { + + public async Task GetAllProductInventory( int accountID, int productID ) { + List list = new List(); + 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 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(); + } + } + + } +} \ No newline at end of file diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/ProjectMistData.cs b/src/MistoxWebsite.Server/Services/DatabaseService/ProjectMistData.cs deleted file mode 100755 index 079764e..0000000 --- a/src/MistoxWebsite.Server/Services/DatabaseService/ProjectMistData.cs +++ /dev/null @@ -1,71 +0,0 @@ -using MistoxWebsite.Server.Entities; -using MySql.Data.MySqlClient; -using System.Data; -using System.Data.Common; - -namespace MistoxWebsite.Server.Services.DatabaseService { - public partial class DatabaseService { - - public async Task GetProjectMistData( int ID ) { - ProjectMistData? items = null; - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - SELECT * FROM ProjectMistData - WHERE AccountID = @AccountID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", ID); - - using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { - while( await reader.ReadAsync() ) { - if( reader == null ) { - break; - } - int _id = reader.GetInt32("AccountID"); - - items = new ProjectMistData() { - AccountID = _id, - }; - } - } - } - return items; - } - - public async Task NewProjectMistData( ProjectMistData data ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - INSERT INTO ProjectMistData - (AccountID) - VALUES - (@AccountID); - "; - - MySqlCommand cmd = new MySqlCommand( command , connection); - cmd.Parameters.AddWithValue("@AccountID", data.AccountID); - - await cmd.ExecuteNonQueryAsync(); - } - } - - public async Task UpdateProjectMistData( ProjectMistData data ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - UPDATE ProjectMistData SET - AccountID = @AccountID - WHERE AccountID = @AccountID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", data.AccountID); - - await cmd.ExecuteReaderAsync(); - } - } - - } -} diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/Receipt.cs b/src/MistoxWebsite.Server/Services/DatabaseService/Receipt.cs index 79e8b87..7ad5f7e 100755 --- a/src/MistoxWebsite.Server/Services/DatabaseService/Receipt.cs +++ b/src/MistoxWebsite.Server/Services/DatabaseService/Receipt.cs @@ -6,7 +6,7 @@ using System.Data.Common; namespace MistoxWebsite.Server.Services.DatabaseService { public partial class DatabaseService { - public async Task GetAllReceipts( Account account ) { + public async Task GetAllReceipts( int accountID ) { List receipts = new List (); using( MySqlConnection connection = GetConnection() ) { connection.Open(); @@ -16,7 +16,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { "; MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); + cmd.Parameters.AddWithValue("@AccountID", accountID); using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { @@ -46,7 +46,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { return receipts.ToArray(); } - public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( Account account ) { + public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( int accountID ) { List<( Receipt, Product )> join = new(); using( MySqlConnection connection = GetConnection() ) { connection.Open(); @@ -58,7 +58,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { "; MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); + cmd.Parameters.AddWithValue("@AccountID", accountID); using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { @@ -103,7 +103,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService { return join.ToArray(); } - public async Task GetReceipt( Account account, Product game ) { + public async Task GetReceipt( int accountID, int gameID ) { Receipt? receipt = null; using( MySqlConnection connection = GetConnection() ) { connection.Open(); @@ -113,8 +113,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService { "; MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); - cmd.Parameters.AddWithValue("@ProductID", game.ID); + cmd.Parameters.AddWithValue("@AccountID", accountID); + cmd.Parameters.AddWithValue("@ProductID", gameID); using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { while( await reader.ReadAsync() ) { diff --git a/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs b/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs deleted file mode 100755 index c7f2cd4..0000000 --- a/src/MistoxWebsite.Server/Services/DatabaseService/WebsiteData.cs +++ /dev/null @@ -1,115 +0,0 @@ -using MistoxWebsite.Server.Entities; -using MySql.Data.MySqlClient; -using System.Data; -using System.Data.Common; - -namespace MistoxWebsite.Server.Services.DatabaseService { - public partial class DatabaseService { - - public async Task GetWebsiteData( Account account ) { - WebSiteData? webSiteData = null; - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - SELECT * FROM WebsiteData - WHERE AccountID = @AccountID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); - - using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) { - while( await reader.ReadAsync() ) { - if( reader == null ) { - break; - } - - int _id = 0; - bool _failedpasswordlock = false; - int _passwordattempts = 5; - int _curpasswordattempts = 0; - string _role = ""; - string _emailtoken = ""; - - if( !reader.IsDBNull( "AccountID" ) ) { - _id = reader.GetInt32( "AccountID" ); - } - if( !reader.IsDBNull( "FailedPasswordLock" ) ) { - _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" ); - } - if( !reader.IsDBNull( "PasswordAttempts" ) ) { - _passwordattempts = reader.GetInt32( "PasswordAttempts" ); - } - if( !reader.IsDBNull( "CurrentPasswordAttempts" ) ) { - _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" ); - } - if( !reader.IsDBNull( "Role" ) ) { - _role = reader.GetString( "Role" ); - } - if( !reader.IsDBNull( "EmailToken" ) ) { - _emailtoken = reader.GetString( "EmailToken" ); - } - - webSiteData = new WebSiteData() { - AccountID = _id, - FailedPasswordLock = _failedpasswordlock, - CurrentPasswordAttempts = _curpasswordattempts, - PasswordAttempts = _passwordattempts, - EmailToken = _emailtoken, - Role = _role, - }; - } - } - } - return webSiteData; - } - - public async Task NewWebsiteData( Account account, WebSiteData data ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - INSERT INTO WebsiteData - (AccountID, FailedPasswordLock, PasswordAttempts, CurrentPasswordAttempts, Role, EmailToken) - VALUES - (@AccountID, @FailedPasswordLock, @PasswordAttempts, @CurrentPasswordAttempts, @Role, @EmailToken); - "; - - MySqlCommand cmd = new MySqlCommand( command , connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); - cmd.Parameters.AddWithValue("@FailedPasswordLock", data.FailedPasswordLock); - cmd.Parameters.AddWithValue("@PasswordAttempts", data.PasswordAttempts); - cmd.Parameters.AddWithValue("@CurrentPasswordAttempts", data.CurrentPasswordAttempts); - cmd.Parameters.AddWithValue("@Role", data.Role); - cmd.Parameters.AddWithValue("@EmailToken", data.EmailToken); - - await cmd.ExecuteNonQueryAsync(); - } - } - - public async Task UpdateWebsiteData( Account account, WebSiteData data ) { - using( MySqlConnection connection = GetConnection() ) { - connection.Open(); - string command = @" - UPDATE WebsiteData SET - FailedPasswordLock = @FailedPasswordLock, - PasswordAttempts = @PasswordAttempts, - CurrentPasswordAttempts = @CurrentPasswordAttempts, - Role = @Role, - EmailToken = @EmailToken - WHERE AccountID = @AccountID; - "; - - MySqlCommand cmd = new MySqlCommand(command, connection); - cmd.Parameters.AddWithValue("@AccountID", account.ID); - cmd.Parameters.AddWithValue("@FailedPasswordLock", data.FailedPasswordLock); - cmd.Parameters.AddWithValue("@PasswordAttempts", data.PasswordAttempts); - cmd.Parameters.AddWithValue("@CurrentPasswordAttempts", data.CurrentPasswordAttempts); - cmd.Parameters.AddWithValue("@Role", data.Role); - cmd.Parameters.AddWithValue("@EmailToken", data.EmailToken); - - await cmd.ExecuteNonQueryAsync(); - } - } - - } -}