-
#region 插入用户汇款充值记录
-
public void UserRemittance(UserAccountRecord userAccountRecord, WebBankAccountRecord webBankAccountRecord)
-
{
-
/// <summary>
-
///用户账户收支明细
-
/// </summary>
-
IUserAccountRecordsRepository IUARRpstry = new UserAccountRecordsRepository();
-
/// <summary>
-
/// 用户账户余额
-
/// </summary>
-
IUserAccountBalancesRepository IUABRpstry = new UserAccountBalancesRepository();
-
/// <summary>
-
/// 网站银行账户收支明细
-
/// </summary>
-
IWebBankAccountRecordsRepository IWBARRpstry = new WebBankAccountRecordsRepository();
-
/// <summary>
-
/// 网站银行账户余额
-
/// </summary>
-
IWebAccountBalancesRepository IWABRpstry = new WebAccountBalancesRepository();
-
using (TransactionScope ts = new TransactionScope())
-
{
-
try
-
{
-
using (TransactionScope ts2 = new TransactionScope())
-
{
-
//第一步:插入新的记录到用户账户收支明细表(UserAccountRecords)
-
#region 第一步:插入新的记录到用户账户收支明细表(UserAccountRecords)
-
try
-
{
-
using (TransactionScope ts3 = new TransactionScope())
-
{
-
try
-
{
-
IUARRpstry.Insert(userAccountRecord);
-
ts3.Complete();
-
}
-
catch (Exception err)
-
{
-
throw err;
-
}
-
finally
-
{
-
ts3.Dispose();
-
}
-
}
-
#endregion
-
//第二步:更新用户账户余额(UserAccountBalances)
-
#region 第二步:更新用户账户余额(UserAccountBalances)
-
Entity.UserAccountBalance userAccountBalanceLinq = (from userAccountBalance in IUABRpstry.GetUserAccountBalances().Where(x => x.UserID.Equals(userAccountRecord.UserID))
-
select userAccountBalance).SingleOrDefault();
-
decimal totalBalance = (from useraccountrecord in IUARRpstry.GetUserAccountRecords().Where(x => x.UserID.Equals(userAccountRecord.UserID) && x.Status.Equals(Entity.UserAccountRecordStatus.Normal))
-
select useraccountrecord.Amount).Sum();
-
userAccountBalanceLinq.TotalBalance = totalBalance;
-
IUABRpstry.Update(userAccountBalanceLinq, Entity.UserAccountBalancesColumnEnum.TotalBalance);
-
#endregion
-
//第三步:插入新的记录到网站银行账户收支明细(WebBankAccountRecords)
-
#region 插入新的记录到网站银行账户收支明细(WebBankAccountRecords)
-
IWBARRpstry.Insert(webBankAccountRecord);
-
#endregion
-
ts2.Complete();
-
}
-
catch (Exception err)
-
{
-
throw err;
-
}
-
finally
-
{
-
ts2.Dispose();
-
}
-
}
-
//第四步:更新网站银行账户余额(WebAccountBalances)
-
#region 第四步:更新网站银行账户余额(WebAccountBalances)
-
decimal BankAccountBalance;
-
int sum = (from balance in IWBARRpstry.GetWebBankAccountRecords().Where(x => x.Status.Equals(Entity.WebBankAccountRecordStatus.Normal))
-
select balance).Count();
-
if (sum == 0)
-
{
-
BankAccountBalance = 0;
-
}
-
else
-
{
-
BankAccountBalance = (from balance in IWBARRpstry.GetWebBankAccountRecords().Where(x => x.Status.Equals(Entity.WebBankAccountRecordStatus.Normal))
-
select balance.Amount).Sum();
-
}
-
Entity.WebAccountBalance webAccountBalance = (from webAB in IWABRpstry.GetWebAccountBalances()
-
select webAB).SingleOrDefault();
-
webAccountBalance.BankAcountBalance = BankAccountBalance;
-
IWABRpstry.Update(webAccountBalance, Entity.WebAccountBalancesColumnEnum.BankAcountBalance);
-
#endregion
-
ts.Complete();
-
}
-
catch (Exception err)
-
{
-
throw err;
-
}
-
finally
-
{
-
ts.Dispose();
-
}
-
}
-
}
-
#endregion
一個傳統的C2C網站的用戶充值的过程
最新推荐文章于 2024-07-10 22:30:38 发布