Remove non-needed pageload object
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
using MistoxWebsite.Server.Services.DatabaseService;
|
||||
using System.Security.Claims;
|
||||
using MistoxWebsite.Server.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MistoxWebsite.Server.Controllers {
|
||||
[ApiController]
|
||||
public class PageLoad : ControllerBase {
|
||||
|
||||
DatabaseService _databaseService;
|
||||
|
||||
public PageLoad( DatabaseService context ) {
|
||||
_databaseService = context;
|
||||
}
|
||||
|
||||
[Route( "api/pageload" )]
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<PageLoadObject>> onPageLoad() {
|
||||
try {
|
||||
if( User.Identity != null && User.Identity.IsAuthenticated ) {
|
||||
string? id = User.FindFirstValue( "ID" );
|
||||
if( !string.IsNullOrEmpty( id ) ) {
|
||||
PageLoadObject test = await _databaseService.getPageLoadObject(int.Parse(id));
|
||||
if (test.user != null){
|
||||
test.Cart = await _databaseService.GetCart( test.user );
|
||||
if( test != null ) {
|
||||
return test;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NotFound();
|
||||
} catch (Exception e) {
|
||||
Console.WriteLine(e.ToString());
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
using MistoxWebsite.Server.Entities;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace MistoxWebsite.Server.Services.DatabaseService {
|
||||
public partial class DatabaseService {
|
||||
|
||||
public async Task<PageLoadObject> getPageLoadObject( int AccountID ) {
|
||||
PageLoadObject account = new PageLoadObject();
|
||||
using( MySqlConnection connection = GetConnection() ) {
|
||||
connection.Open();
|
||||
string command = @"
|
||||
SELECT * FROM Account
|
||||
INNER JOIN WebsiteData
|
||||
ON Account.ID = WebsiteData.AccountID
|
||||
WHERE ID = @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(0);
|
||||
string _username = reader.GetString(1);
|
||||
string _email = reader.GetString(2);
|
||||
bool _emailVerified = reader.GetBoolean(3);
|
||||
string _passwordhash = reader.GetString(4);
|
||||
bool _failedPasswordLock = reader.GetBoolean(6);
|
||||
int _passwordAttempts = reader.GetInt32(7);
|
||||
int _currentPasswordAttempts = reader.GetInt32(8);
|
||||
string _role = reader.GetString(9);
|
||||
string _emailToken = reader.GetString(10);
|
||||
|
||||
account.claims = new AccountClaims() {
|
||||
Email = _email,
|
||||
EmailVerified = _emailVerified.ToString(),
|
||||
FailedPasswordLock = _failedPasswordLock.ToString(),
|
||||
Role = _role,
|
||||
UserName = _username,
|
||||
};
|
||||
|
||||
account.user = new Account() {
|
||||
ID = _id,
|
||||
UserName = _username,
|
||||
Email = _email,
|
||||
EmailVerified = _emailVerified,
|
||||
PasswordHash = _passwordhash,
|
||||
SiteData = new WebSiteData() {
|
||||
AccountID = _id,
|
||||
CurrentPasswordAttempts = _currentPasswordAttempts,
|
||||
PasswordAttempts = _passwordAttempts,
|
||||
EmailToken = _emailToken,
|
||||
FailedPasswordLock = _failedPasswordLock,
|
||||
Role = _role,
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
List<Product> tempProds = new List<Product>();
|
||||
List<Receipt> tempReceipt = new List<Receipt>();
|
||||
|
||||
command = @"
|
||||
SELECT * FROM Product
|
||||
LEFT JOIN Receipt
|
||||
ON ID = Receipt.ProductID
|
||||
WHERE AccountID is Null or AccountID = @AccountID;
|
||||
";
|
||||
|
||||
MySqlCommand cmd2 = new MySqlCommand(command, connection);
|
||||
cmd2.Parameters.AddWithValue("@AccountID", AccountID);
|
||||
|
||||
using( DbDataReader reader = await cmd2.ExecuteReaderAsync() ) {
|
||||
while (await reader.ReadAsync()) {
|
||||
if (reader == null) {
|
||||
break;
|
||||
}
|
||||
|
||||
int _productID = !await reader.IsDBNullAsync(0) ? reader.GetInt32(0) : -1;
|
||||
string _gameName = !await reader.IsDBNullAsync(1) ? reader.GetString(1) : "";
|
||||
string _gameDesc = !await reader.IsDBNullAsync(2) ? reader.GetString(2) : "";
|
||||
string _gameImg = !await reader.IsDBNullAsync(3) ? reader.GetString(3) : "";
|
||||
int _gameCost = !await reader.IsDBNullAsync(4) ? reader.GetInt32(4) : 37707;
|
||||
string _gameURL = !await reader.IsDBNullAsync(5) ? reader.IsDBNull(5) ? "" : reader.GetString(5) : "Something not common";
|
||||
int _receiptAccountID = !await reader.IsDBNullAsync(6) ? reader.IsDBNull(6) ? -1 : reader.GetInt32(6) : -1;
|
||||
string _receiptID = !await reader.IsDBNullAsync(8) ? reader.IsDBNull(8) ? "" : reader.GetString(8) : "";
|
||||
DateTime _receiptTime = !await reader.IsDBNullAsync(10) ? reader.GetDateTime(10) : DateTime.Now;
|
||||
|
||||
string[] _imageList = _gameImg.Split('|', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
tempProds.Add(new Product {
|
||||
ID = _productID,
|
||||
Cost = _gameCost,
|
||||
Description = _gameDesc,
|
||||
Name = _gameName,
|
||||
URL = _gameURL,
|
||||
Images = _imageList
|
||||
});
|
||||
|
||||
if (_receiptAccountID != -1) {
|
||||
tempReceipt.Add(new Receipt {
|
||||
AccountID = _receiptAccountID,
|
||||
ProductID = _productID,
|
||||
ReceiptID = _receiptID,
|
||||
Time = _receiptTime
|
||||
});
|
||||
}
|
||||
|
||||
account.products = tempProds.ToArray();
|
||||
account.receipts = tempReceipt.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user