一個傳統的C2C網站的用戶充值的过程-阿里云开发者社区

开发者社区> 云计算> 正文
登录阅读全文

一個傳統的C2C網站的用戶充值的过程

简介:

image 


  1. #region 插入用户汇款充值记录
    
  2.         public void UserRemittance(UserAccountRecord userAccountRecord, WebBankAccountRecord webBankAccountRecord)
    
  3.         {
    
  4.             /// <summary>
    
  5.             ///用户账户收支明细
    
  6.             /// </summary>
    
  7.             IUserAccountRecordsRepository IUARRpstry = new UserAccountRecordsRepository();
    
  8.             /// <summary>
    
  9.             ///  用户账户余额
    
  10.             /// </summary>
    
  11.             IUserAccountBalancesRepository IUABRpstry = new UserAccountBalancesRepository();
    
  12.             /// <summary>
    
  13.             /// 网站银行账户收支明细
    
  14.             /// </summary>
    
  15.             IWebBankAccountRecordsRepository IWBARRpstry = new WebBankAccountRecordsRepository();
    
  16.             /// <summary>
    
  17.             /// 网站银行账户余额
    
  18.             /// </summary>
    
  19.             IWebAccountBalancesRepository IWABRpstry = new WebAccountBalancesRepository();
    
  20.             using (TransactionScope ts = new TransactionScope())
    
  21.             {
    
  22.                 try
    
  23.                 {
    
  24.                     using (TransactionScope ts2 = new TransactionScope())
    
  25.                     {
    
  26.                         //第一步:插入新的记录到用户账户收支明细表(UserAccountRecords)
    
  27.                         #region 第一步:插入新的记录到用户账户收支明细表(UserAccountRecords)
    
  28.                         try
    
  29.                         {
    
  30.                             using (TransactionScope ts3 = new TransactionScope())
    
  31.                             {
    
  32.                                 try
    
  33.                                 {
    
  34.                                     IUARRpstry.Insert(userAccountRecord);
    
  35.                                     ts3.Complete();
    
  36.                                 }
    
  37.                                 catch (Exception err)
    
  38.                                 {
    
  39.                                     throw err;
    
  40.                                 }
    
  41.                                 finally
    
  42.                                 {
    
  43.                                     ts3.Dispose();
    
  44.                                 }
    
  45.                             }
    
  46.                         #endregion
    
  47.                         //第二步:更新用户账户余额(UserAccountBalances)
    
  48.                         #region 第二步:更新用户账户余额(UserAccountBalances)
    
  49.                             Entity.UserAccountBalance userAccountBalanceLinq = (from userAccountBalance in IUABRpstry.GetUserAccountBalances().Where(x => x.UserID.Equals(userAccountRecord.UserID))
    
  50.                                                                                 select userAccountBalance).SingleOrDefault();
    
  51.                             decimal totalBalance = (from useraccountrecord in IUARRpstry.GetUserAccountRecords().Where(x => x.UserID.Equals(userAccountRecord.UserID) && x.Status.Equals(Entity.UserAccountRecordStatus.Normal))
    
  52.                                                     select useraccountrecord.Amount).Sum();
    
  53.                             userAccountBalanceLinq.TotalBalance = totalBalance;
    
  54.                             IUABRpstry.Update(userAccountBalanceLinq, Entity.UserAccountBalancesColumnEnum.TotalBalance);
    
  55.                             #endregion
    
  56.                         //第三步:插入新的记录到网站银行账户收支明细(WebBankAccountRecords)
    
  57.                         #region 插入新的记录到网站银行账户收支明细(WebBankAccountRecords)
    
  58.                             IWBARRpstry.Insert(webBankAccountRecord);
    
  59.                             #endregion
    
  60.                         ts2.Complete();
    
  61.                         }
    
  62.                         catch (Exception err)
    
  63.                         {
    
  64.                             throw err;
    
  65.                         }
    
  66.                         finally
    
  67.                         {
    
  68.                             ts2.Dispose();
    
  69.                         }
    
  70.                     }
    
  71.                     //第四步:更新网站银行账户余额(WebAccountBalances)
    
  72.                     #region 第四步:更新网站银行账户余额(WebAccountBalances)
    
  73.                     decimal BankAccountBalance;
    
  74.                     int sum = (from balance in IWBARRpstry.GetWebBankAccountRecords().Where(x => x.Status.Equals(Entity.WebBankAccountRecordStatus.Normal))
    
  75.                                select balance).Count();
    
  76.                     if (sum == 0)
    
  77.                     {
    
  78.                         BankAccountBalance = 0;
    
  79.                     }
    
  80.                     else
    
  81.                     {
    
  82.                         BankAccountBalance = (from balance in IWBARRpstry.GetWebBankAccountRecords().Where(x => x.Status.Equals(Entity.WebBankAccountRecordStatus.Normal))
    
  83.                                               select balance.Amount).Sum();
    
  84.                     }
    
  85.                     Entity.WebAccountBalance webAccountBalance = (from webAB in IWABRpstry.GetWebAccountBalances()
    
  86.                                                                    select webAB).SingleOrDefault();
    
  87.                     webAccountBalance.BankAcountBalance = BankAccountBalance;
    
  88.                     IWABRpstry.Update(webAccountBalance, Entity.WebAccountBalancesColumnEnum.BankAcountBalance);
    
  89.                     #endregion
    
  90.                     ts.Complete();
    
  91.                 }
    
  92.                 catch (Exception err)
    
  93.                 {
    
  94.                     throw err;
    
  95.                 }
    
  96.                 finally
    
  97.                 {
    
  98.                     ts.Dispose();
    
  99.                 }
    
  100.             }
    
  101.         }
    
  102.         #endregion
本文转自博客园张占岭(仓储大叔)的博客,原文链接:一個傳統的C2C網站的用戶充值的过程,如需转载请自行联系原博主。

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享: