2016-04-19 25 views
0

RPSPサーバーは一度に1つのトランザクションしか処理できないため、支払いが正常に完了した後にトップアップバウチャーコードを作成しようとするコードがあります。 MVCコントロールアクション内に次のコードがあります。これは、バウチャーコードを最初の試みで作成できなかった場合、この回数を最大5回までループする最良の方法です。失敗した場合のアクションのループ

//Check the Realex response Code 
if (tResp.ResultCode == 0) 
{      
    try 
    { 
     //Create the Voucher code 
     ViewBag.VendCode = createVoucher(topupKeypadNumber.ToString(), topupAmount.ToString()); 
    } 
    catch (Exception ex) 
    { 
     //SET THE VARIABLES TO BE DISPLAYED ON THE VEND CODE DISPLAY PAGE 
     System.Diagnostics.EventLog.WriteEntry("Application", "GENERAL ERROR : " + ex.Message, System.Diagnostics.EventLogEntryType.Information); 
     ViewBag.Title = "Vend Code Error"; 
     ViewBag.Message = "An error has occurred while retrieving your vend code. Please contact our customer service team."; 
     return View("Info"); 
    } 
    //SET THE VARIABLES TO BE DISPLAYED ON THE VEND CODE DISPLAY PAGE 
    ViewBag.Title = "Issue Vend Code"; 
    ViewBag.Message = ViewBag.VendCode; 
    return View("Success"); 
} 
+0

回答が役に立ちましたか?あなたはまだ応答していません。 –

+0

こんにちはpsyLogic私は試しにロジックを使用しています。 – Jay

答えて

1

これを試してください。

if (tResp.ResultCode == 0) 
{  
    int maximumRetryLimit=5; 
    int retryCount=0; 
    bool isVoucherCreated;  
    try 
    { 
     while(retryCount<=maximumRetryLimit) 
     { //Create the Voucher code 
     ViewBag.VendCode = createVoucher(topupKeypadNumber.ToString(), topupAmount.ToString()); 
     if(ViewBag.VendCode!=null) 
     { 
      isVoucherCreated=true; 
      break; 
     } 
     ++retryCount; 
     } 
    } 
    catch (Exception ex) 
    { 
     //SET THE VARIABLES TO BE DISPLAYED ON THE VEND CODE DISPLAY PAGE 
     System.Diagnostics.EventLog.WriteEntry("Application", "GENERAL ERROR : " + ex.Message, System.Diagnostics.EventLogEntryType.Information); 
     ViewBag.Title = "Vend Code Error"; 
     ViewBag.Message = "An error has occurred while retrieving your vend code. Please contact our customer service team."; 
     return View("Info"); 
    } 
    //SET THE VARIABLES TO BE DISPLAYED ON THE VEND CODE DISPLAY PAGE 
    if(isVoucherCreated) 
    { 
     ViewBag.Title = "Issue Vend Code"; 
     ViewBag.Message = ViewBag.VendCode; 
     return View("Success"); 
    } 
    else 
    { 
     ViewBag.Title = "Vend Code Error"; 
     ViewBag.Message = "An error has occurred while retrieving your vend code. Please contact our customer service team."; 
     return View("Info"); 
    } 
} 
関連する問題