Allow saving stocks to the database
This commit is contained in:
@@ -37,7 +37,7 @@
|
|||||||
<div>@cur.Symbol</div>
|
<div>@cur.Symbol</div>
|
||||||
<div>@cur.Quantity</div>
|
<div>@cur.Quantity</div>
|
||||||
<div>@cur.PurchasePrice</div>
|
<div>@cur.PurchasePrice</div>
|
||||||
<div>@cur.PurchaseDate.ToString("M-D-YYYY")</div>
|
<div>@cur.PurchaseDate.ToString("M-dd-yyyy")</div>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -54,9 +54,12 @@
|
|||||||
<button disabled>@trainButtonText</button>
|
<button disabled>@trainButtonText</button>
|
||||||
<button disabled>@predictButtonText</button>
|
<button disabled>@predictButtonText</button>
|
||||||
}
|
}
|
||||||
<button @onclick="buyStock">Buy Stock</button>
|
<br/>
|
||||||
<input placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
|
<div>
|
||||||
<input placeholder="1.0" @bind="buyStockQuantity" />
|
<input placeholder="Stock Symbol [NVDA]" @bind="buyStockSymbol" />
|
||||||
|
<input placeholder="Stock Quantity [1.0]" @bind="buyStockQuantity" />
|
||||||
|
<button @onclick="buyStock">Buy Stock</button>
|
||||||
|
</div>
|
||||||
<span>@resultError</span>
|
<span>@resultError</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -120,7 +123,7 @@
|
|||||||
string dbPrefix = $"[{userName.ToLower()}]:"; // Set the DB prefix for the get and set
|
string dbPrefix = $"[{userName.ToLower()}]:"; // Set the DB prefix for the get and set
|
||||||
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
|
string passwordhash = dbDriver.Get( dbPrefix + "password" ); // Pull the password hash
|
||||||
if (BCrypt.Verify( passWord, passwordhash )){ // If the password is valid
|
if (BCrypt.Verify( passWord, passwordhash )){ // If the password is valid
|
||||||
List<PurchasedStock>? stocks = JsonConvert.DeserializeObject<List<PurchasedStock>>( dbDriver.Get( dbPrefix + "stock-data" ) );
|
List<PurchasedStock>? stocks = JsonConvert.DeserializeObject<List<PurchasedStock>>( dbDriver.Get( dbPrefix + "Stocks" ) );
|
||||||
Session = new loginSession(){
|
Session = new loginSession(){
|
||||||
UserName = userName.ToLower(),
|
UserName = userName.ToLower(),
|
||||||
TrackedStocks = stocks != null ? stocks : new List<PurchasedStock>()
|
TrackedStocks = stocks != null ? stocks : new List<PurchasedStock>()
|
||||||
@@ -225,7 +228,7 @@
|
|||||||
float StockPrice = 0;
|
float StockPrice = 0;
|
||||||
void buyStock(){
|
void buyStock(){
|
||||||
if (Session != null){
|
if (Session != null){
|
||||||
|
string dbPrefix = $"[{userName.ToLower()}]:";
|
||||||
// Try Parse the quantitiy input
|
// Try Parse the quantitiy input
|
||||||
bool success = float.TryParse(buyStockQuantity, out float QuantityResult);
|
bool success = float.TryParse(buyStockQuantity, out float QuantityResult);
|
||||||
if (!success){
|
if (!success){
|
||||||
@@ -240,13 +243,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the item
|
// Add the stock
|
||||||
Session.TrackedStocks.Add( new PurchasedStock(){
|
Session.TrackedStocks.Add( new PurchasedStock(){
|
||||||
Symbol = buyStockSymbol.ToLower(),
|
Symbol = buyStockSymbol.ToUpper(),
|
||||||
PurchasePrice = StockPrice,
|
PurchasePrice = StockPrice,
|
||||||
Quantity = QuantityResult,
|
Quantity = QuantityResult,
|
||||||
PurchaseDate = DateTime.Now
|
PurchaseDate = DateTime.Now
|
||||||
} );
|
} );
|
||||||
|
dbDriver.Set( dbPrefix + "Stocks", Newtonsoft.Json.JsonConvert.SerializeObject(Session.TrackedStocks) );
|
||||||
|
|
||||||
// Reset the Impodent Key
|
// Reset the Impodent Key
|
||||||
result = PaymentProcessor.CreatePayment();
|
result = PaymentProcessor.CreatePayment();
|
||||||
|
|||||||
Reference in New Issue
Block a user