Update SQL to match new database structure
This commit is contained in:
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -13,8 +13,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
string command = @"
|
string command = @"
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM Account
|
FROM Account
|
||||||
Left Join WebsiteData
|
|
||||||
On Account.ID = WebsiteData.AccountID
|
|
||||||
WHERE UserName = @UorE OR Email = @UorE;
|
WHERE UserName = @UorE OR Email = @UorE;
|
||||||
";
|
";
|
||||||
|
|
||||||
@@ -32,7 +30,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
string _email = reader.GetString("Email");
|
string _email = reader.GetString("Email");
|
||||||
bool _emailVerified = reader.GetBoolean("EmailVerified");
|
bool _emailVerified = reader.GetBoolean("EmailVerified");
|
||||||
string _passwordhash = reader.GetString("PasswordHash");
|
string _passwordhash = reader.GetString("PasswordHash");
|
||||||
|
|
||||||
bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" );
|
bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" );
|
||||||
int _passwordattempts = reader.GetInt32( "PasswordAttempts" );
|
int _passwordattempts = reader.GetInt32( "PasswordAttempts" );
|
||||||
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
|
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
|
||||||
@@ -45,14 +42,11 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
Email = _email,
|
Email = _email,
|
||||||
EmailVerified = _emailVerified,
|
EmailVerified = _emailVerified,
|
||||||
PasswordHash = _passwordhash,
|
PasswordHash = _passwordhash,
|
||||||
SiteData = new WebSiteData() {
|
|
||||||
AccountID = _id,
|
|
||||||
CurrentPasswordAttempts = _curpasswordattempts,
|
CurrentPasswordAttempts = _curpasswordattempts,
|
||||||
PasswordAttempts = _passwordattempts,
|
PasswordAttempts = _passwordattempts,
|
||||||
EmailToken = _emailtoken,
|
EmailToken = _emailtoken,
|
||||||
FailedPasswordLock = _failedpasswordlock,
|
FailedPasswordLock = _failedpasswordlock,
|
||||||
Role = _role,
|
Role = _role,
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,15 +54,13 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Account?> GetAccountByID( int ID ) {
|
public async Task<Account?> GetAccount( int ID ) {
|
||||||
Account? account = null;
|
Account? account = null;
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
string command = @"
|
string command = @"
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM Account
|
FROM Account
|
||||||
Left Join WebsiteData
|
|
||||||
On Account.ID = WebsiteData.AccountID
|
|
||||||
WHERE ID = @ID;
|
WHERE ID = @ID;
|
||||||
";
|
";
|
||||||
|
|
||||||
@@ -85,7 +77,6 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
string _email = reader.GetString("Email");
|
string _email = reader.GetString("Email");
|
||||||
bool _emailVerified = reader.GetBoolean("EmailVerified");
|
bool _emailVerified = reader.GetBoolean("EmailVerified");
|
||||||
string _passwordhash = reader.GetString("PasswordHash");
|
string _passwordhash = reader.GetString("PasswordHash");
|
||||||
|
|
||||||
bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" );
|
bool _failedpasswordlock = reader.GetBoolean( "FailedPasswordLock" );
|
||||||
int _passwordattempts = reader.GetInt32( "PasswordAttempts" );
|
int _passwordattempts = reader.GetInt32( "PasswordAttempts" );
|
||||||
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
|
int _curpasswordattempts = reader.GetInt32( "CurrentPasswordAttempts" );
|
||||||
@@ -98,14 +89,11 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
Email = _email,
|
Email = _email,
|
||||||
EmailVerified = _emailVerified,
|
EmailVerified = _emailVerified,
|
||||||
PasswordHash = _passwordhash,
|
PasswordHash = _passwordhash,
|
||||||
SiteData = new WebSiteData() {
|
|
||||||
AccountID = _id,
|
|
||||||
CurrentPasswordAttempts = _passwordattempts,
|
CurrentPasswordAttempts = _passwordattempts,
|
||||||
PasswordAttempts = _passwordattempts,
|
PasswordAttempts = _passwordattempts,
|
||||||
EmailToken = _emailtoken,
|
EmailToken = _emailtoken,
|
||||||
FailedPasswordLock = _failedpasswordlock,
|
FailedPasswordLock = _failedpasswordlock,
|
||||||
Role = _role,
|
Role = _role,
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -113,65 +101,44 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetAccount( Account Update ) {
|
public async Task SetAccount( Account Profile ) {
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
string command = @"
|
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,
|
UserName = @UserName,
|
||||||
Email = @Email,
|
Email = @Email,
|
||||||
EmailVerified = @EmailVerified,
|
EmailVerified = @EmailVerified,
|
||||||
PasswordHash = @PasswordHash
|
PasswordHash = @PasswordHash,
|
||||||
WHERE ID = @ID;
|
FailedPasswordLock = @FailedPasswordLock,
|
||||||
";
|
PasswordAttempts = @PasswordAttempts,
|
||||||
|
CurrentPasswordAttempts = @CurrentPasswordAttempts,
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
Role = @Role,
|
||||||
cmd.Parameters.AddWithValue("@UserName", Update.UserName);
|
EmailToken = @EmailToken;
|
||||||
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;
|
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand( command , connection);
|
MySqlCommand cmd = new MySqlCommand( command , connection);
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Profile.ID);
|
||||||
cmd.Parameters.AddWithValue("@UserName", Profile.UserName);
|
cmd.Parameters.AddWithValue("@UserName", Profile.UserName);
|
||||||
cmd.Parameters.AddWithValue("@Email", Profile.Email);
|
cmd.Parameters.AddWithValue("@Email", Profile.Email);
|
||||||
cmd.Parameters.AddWithValue("@EmailVerified", Profile.EmailVerified);
|
cmd.Parameters.AddWithValue("@EmailVerified", Profile.EmailVerified);
|
||||||
cmd.Parameters.AddWithValue("@PasswordHash", Profile.PasswordHash);
|
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() ) {
|
await cmd.ExecuteNonQueryAsync();
|
||||||
while( await reader.ReadAsync() ) {
|
|
||||||
if( reader == null ) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int _id = reader.GetInt32("ID");
|
|
||||||
Profile.ID = _id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await NewWebsiteData( Profile, Profile.SiteData );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteAccount( Account Profile ) {
|
public async Task DeleteAccount( int ID ) {
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
MySqlCommand cmd;
|
MySqlCommand cmd;
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -181,10 +148,9 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
DELETE FROM AccountInventory WHERE AccountID = @ID;
|
DELETE FROM AccountInventory WHERE AccountID = @ID;
|
||||||
DELETE FROM ProjectMistData WHERE AccountID = @ID;
|
DELETE FROM ProjectMistData WHERE AccountID = @ID;
|
||||||
DELETE FROM Cart WHERE AccountID = @ID;
|
DELETE FROM Cart WHERE AccountID = @ID;
|
||||||
DELETE FROM WebsiteData WHERE AccountID = @ID;
|
|
||||||
";
|
";
|
||||||
cmd = new MySqlCommand( command, connection );
|
cmd = new MySqlCommand( command, connection );
|
||||||
cmd.Parameters.AddWithValue("@ID", Profile.ID);
|
cmd.Parameters.AddWithValue("@ID", ID);
|
||||||
|
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<UserInventory[]> GetInventory( Account account, Product product ) {
|
|
||||||
List<UserInventory> list = new List<UserInventory>();
|
|
||||||
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<UserInventory> 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
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ using System.Data.Common;
|
|||||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||||
public partial class DatabaseService {
|
public partial class DatabaseService {
|
||||||
|
|
||||||
public async Task<Cart[]> GetCart( Account account ) {
|
public async Task<Cart[]> GetCart( int accountID ) {
|
||||||
List<Cart> list = new List<Cart>();
|
List<Cart> list = new List<Cart>();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -16,7 +16,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
cmd.Parameters.AddWithValue("@AccountID", account.ID);
|
cmd.Parameters.AddWithValue("@AccountID", accountID);
|
||||||
|
|
||||||
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
||||||
while( await reader.ReadAsync() ) {
|
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() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
string command = @"
|
string command = @"
|
||||||
@@ -73,7 +73,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand( command , connection);
|
MySqlCommand cmd = new MySqlCommand( command , connection);
|
||||||
cmd.Parameters.AddWithValue("@AccountID", account.ID);
|
cmd.Parameters.AddWithValue("@AccountID", accountID);
|
||||||
|
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,20 +77,27 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
return items.ToArray();
|
return items.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NewProduct(Product Item) {
|
public async Task SetProduct(Product Item) {
|
||||||
using (MySqlConnection connection = GetConnection()) {
|
using (MySqlConnection connection = GetConnection()) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
string command = @"
|
string command = @"
|
||||||
INSERT INTO Product
|
INSERT INTO Product
|
||||||
(Name, Description, Cost, URL)
|
(ID,Name,Description,Cost,URL)
|
||||||
VALUES
|
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
|
SELECT ID FROM Product
|
||||||
WHERE Name = @Name;
|
WHERE Name = @Name;
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
|
cmd.Parameters.AddWithValue("@ID", Item.ID);
|
||||||
cmd.Parameters.AddWithValue("@Name", Item.Name);
|
cmd.Parameters.AddWithValue("@Name", Item.Name);
|
||||||
cmd.Parameters.AddWithValue("@Description", Item.Description);
|
cmd.Parameters.AddWithValue("@Description", Item.Description);
|
||||||
cmd.Parameters.AddWithValue("@Cost", Item.Cost);
|
cmd.Parameters.AddWithValue("@Cost", Item.Cost);
|
||||||
@@ -109,36 +116,10 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpdateProduct(Product Item) {
|
public async Task DeleteProduct(int ID) {
|
||||||
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) {
|
|
||||||
using (MySqlConnection connection = GetConnection()) {
|
using (MySqlConnection connection = GetConnection()) {
|
||||||
|
|
||||||
await DeleteAllImages(ProductID);
|
await DeleteAllImages(ID);
|
||||||
|
|
||||||
connection.Open();
|
connection.Open();
|
||||||
string command = @"
|
string command = @"
|
||||||
@@ -146,7 +127,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
WHERE ID = @ID;
|
WHERE ID = @ID;
|
||||||
";
|
";
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
cmd.Parameters.AddWithValue("@ID", ProductID);
|
cmd.Parameters.AddWithValue("@ID", ID);
|
||||||
|
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<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,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<ProjectMistData?> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ using System.Data.Common;
|
|||||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||||
public partial class DatabaseService {
|
public partial class DatabaseService {
|
||||||
|
|
||||||
public async Task<Receipt[]> GetAllReceipts( Account account ) {
|
public async Task<Receipt[]> GetAllReceipts( int accountID ) {
|
||||||
List<Receipt> receipts = new List<Receipt> ();
|
List<Receipt> receipts = new List<Receipt> ();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -16,7 +16,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
cmd.Parameters.AddWithValue("@AccountID", account.ID);
|
cmd.Parameters.AddWithValue("@AccountID", accountID);
|
||||||
|
|
||||||
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
||||||
while( await reader.ReadAsync() ) {
|
while( await reader.ReadAsync() ) {
|
||||||
@@ -46,7 +46,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
return receipts.ToArray();
|
return receipts.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( Account account ) {
|
public async Task<( Receipt, Product )[]> GetAllReceiptsJoinedToProduct( int accountID ) {
|
||||||
List<( Receipt, Product )> join = new();
|
List<( Receipt, Product )> join = new();
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -58,7 +58,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
cmd.Parameters.AddWithValue("@AccountID", account.ID);
|
cmd.Parameters.AddWithValue("@AccountID", accountID);
|
||||||
|
|
||||||
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
||||||
while( await reader.ReadAsync() ) {
|
while( await reader.ReadAsync() ) {
|
||||||
@@ -103,7 +103,7 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
return join.ToArray();
|
return join.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Receipt?> GetReceipt( Account account, Product game ) {
|
public async Task<Receipt?> GetReceipt( int accountID, int gameID ) {
|
||||||
Receipt? receipt = null;
|
Receipt? receipt = null;
|
||||||
using( MySqlConnection connection = GetConnection() ) {
|
using( MySqlConnection connection = GetConnection() ) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
@@ -113,8 +113,8 @@ namespace MistoxWebsite.Server.Services.DatabaseService {
|
|||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
cmd.Parameters.AddWithValue("@AccountID", account.ID);
|
cmd.Parameters.AddWithValue("@AccountID", accountID);
|
||||||
cmd.Parameters.AddWithValue("@ProductID", game.ID);
|
cmd.Parameters.AddWithValue("@ProductID", gameID);
|
||||||
|
|
||||||
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
using( DbDataReader reader = await cmd.ExecuteReaderAsync() ) {
|
||||||
while( await reader.ReadAsync() ) {
|
while( await reader.ReadAsync() ) {
|
||||||
|
|||||||
@@ -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<WebSiteData?> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user