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

image 


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

你可能感兴趣的:(过程)