Allow selling

This commit is contained in:
2026-03-09 17:12:18 -07:00
parent ac67be137c
commit b757672bdf
3 changed files with 71 additions and 23 deletions
@@ -60,6 +60,40 @@ namespace Controllers.Payment {
return (false, e.ToString());
}
}
public (bool, string) TrySell(string ImpodentKey, float Price) {
// Find the impotency key
ImpodentKey? found = null;
foreach( ImpodentKey key in ImpodentKeys) {
if (key.Key == ImpodentKey) {
found = key;
break;
}
}
if (found == null) {
return (false, "Payment session closed or never existed");
}
// Make sure the database is injected correctly
if (_DBdriver == null) {
found.Processed = true;
return (false, "The Database cannot be loaded");
}
// Get the users money
string dbPrefix = $"[{found.User.ToLower()}]:";
bool passed = float.TryParse(_DBdriver.Get( dbPrefix + "money" ), out float result);
if (!passed) {
found.Processed = true;
return (false, "Unable to parse money from the database");
}
// Add the money and save
_DBdriver.Set( dbPrefix + "money", (result + Price).ToString());
found.PaymentSuccess = true;
found.Processed = true;
return (true, "");
}
}
class ImpodentKey {