Skip to content

Instantly share code, notes, and snippets.

@tzamora
Created June 10, 2016 20:19
Show Gist options
  • Save tzamora/8ae07e6304553e946796280a050aab34 to your computer and use it in GitHub Desktop.
Save tzamora/8ae07e6304553e946796280a050aab34 to your computer and use it in GitHub Desktop.
public static List<Wallet> GetWallets(Database Db, User user)
{
double pendingCredits = Wallet.GetPendingCredits(Db, user.customerId);
/*
* Get the customer's current sum of activity this week. According to the SP,
* it follows this formula:
* total = amountWon + creditAdjustment + casinoAmountWon
* - amountLost - debitAdjustment - casinoAmountLost
*/
//double thisWeeksActivity = 0;
var parameters = new Dictionary<string, object> {
{ "customerID", user.customerId }
};
object result = Db.ExecuteStoredProcedureScalar("spInetGetThisWeeksFigure", parameters);
double thisWeeksActivity = (!Convert.IsDBNull(result)) ? double.Parse(result.ToString()) : 0;
/*
* Now fetch balances
*/
IDataReader data = Db.ExecuteStoredProcedure("spInetGetCustomerBalances", parameters);
/*
* Every user has precisely two wallets, "cash" and "free-play." These are both
* constructed from the same (single) customer balance record.
*/
Wallet cash = new Wallet("cash");
Wallet freeplay = new Wallet("free-play");
if (data.Read())
{
bool weeklyLimits = (!Convert.IsDBNull(data["WeeklyLimitFlag"])) && Convert.ToChar(data["WeeklyLimitFlag"]) == 'Y';
/* CASH */
cash.pendingBalance = Convert.ToDouble(data["PendingWagerBalance"]) / 100;
cash.pendingWagers = Convert.ToInt32(data["PendingWagerCount"]);
cash.balance = Convert.ToDouble(data["CurrentBalance"]) / 100;
cash.balance += Convert.ToDouble(data["CreditLimit"]) / 100;
cash.creditLimit = Convert.ToDouble(data["CreditLimit"])/100;
cash.balance += Convert.ToDouble(data["CasinoBalance"]) / 100;
cash.casinoBalance = Convert.ToDouble(data["CasinoBalance"]) / 100;
cash.currentBalance = Convert.ToDouble(data["CurrentBalance"]) / 100;
cash.balance += pendingCredits / 100;
if (weeklyLimits)
{
cash.balance += thisWeeksActivity / 100;
cash.balance -= Convert.ToDouble(data["PendingWagerBalance"]) / 100;
}
else
{
/*
* If the user has been extended credit from the sportsbook, then
* subtract their pending wager balance from their available balance.
*/
if (user.isCredit)
{
cash.balance -= Convert.ToDouble(data["PendingWagerBalance"]) / 100;
}
}
/* FREE PLAY */
freeplay.balance = Convert.ToDouble(data["FreePlayBalance"]) / 100;
freeplay.pendingBalance = Convert.ToDouble(data["FreePlayPendingBalance"]) / 100;
freeplay.pendingWagers = Convert.ToInt32(data["FreePlayPendingCount"]);
}
data.Close();
List<Wallet> wallets = new List<Wallet>();
cash.balance = Math.Round(cash.balance, 2, MidpointRounding.AwayFromZero);
cash.creditLimit = Math.Round(cash.creditLimit, 2, MidpointRounding.AwayFromZero);
cash.casinoBalance = Math.Round(cash.casinoBalance, 2, MidpointRounding.AwayFromZero);
cash.currentBalance = Math.Round(cash.currentBalance, 2, MidpointRounding.AwayFromZero);
cash.pendingBalance = Math.Round(cash.pendingBalance, 2, MidpointRounding.AwayFromZero);
freeplay.balance = Math.Round(freeplay.balance, 2, MidpointRounding.AwayFromZero);
freeplay.pendingBalance = Math.Round(freeplay.pendingBalance, 2, MidpointRounding.AwayFromZero);
wallets.Add(cash);
wallets.Add(freeplay);
return wallets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment