Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.74 KB | None | 0 0
  1. private async Task<BillingCodesValidationResult> BillingCodesCheck(ElectronicI9 electronicI9)
  2.         {
  3.             var generalParametersDisplayRules = await _displayRulesRepository.GetGeneralParametersDisplayRulesForReportOrderAsync(electronicI9.ClientId);
  4.  
  5.             var client = await _clientService.GetClientAsync(electronicI9.ClientId);
  6.             var billingCodeWebNames = await _billingCodeRepository.GetBillingCodeWebNameAsync(electronicI9.ClientId) ?? new BillingCodeWebName();
  7.  
  8.             var allowedNumber = client.AllowedBillingCodesTextBoxNumber + client.AllowedBillingCodesDropDownNumber;
  9.  
  10.             var billingCodes = new List<BillingCodeValidationResult>
  11.             {
  12.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName1, Value = electronicI9.BillingInfo.BillingCodeNum1 },
  13.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName2, Value = electronicI9.BillingInfo.BillingCodeNum2 },
  14.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName3, Value = electronicI9.BillingInfo.BillingCodeNum3 },
  15.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName4, Value = electronicI9.BillingInfo.BillingCodeNum4 },
  16.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName5, Value = electronicI9.BillingInfo.BillingCodeNum5 },
  17.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName6, Value = electronicI9.BillingInfo.BillingCodeNum6 },
  18.                 new BillingCodeValidationResult {Name = billingCodeWebNames.BillingCodeWebName7, Value = electronicI9.BillingInfo.BillingCodeNum7 }
  19.             };
  20.  
  21.             var billingCodeChecked = new bool[billingCodes.Count];
  22.  
  23.             for (int i = 1; i <= client.AllowedBillingCodesDropDownNumber; i++)
  24.             {
  25.                 var billingCodesGroup = await _billingCodeRepository.GetBillingCodesAsync(client.ClientId, i);
  26.                 var billingCodeValues = billingCodesGroup.Select(b => b.BillingCodeName);
  27.  
  28.                 if (!billingCodeValues.Contains(billingCodes[i - 1].Value))
  29.                 {
  30.                     billingCodeChecked[i - 1] = true;
  31.                 }
  32.             }
  33.  
  34.             var firstBillingCodeInput = billingCodes[client.AllowedBillingCodesDropDownNumber];
  35.  
  36.             firstBillingCodeInput.Is6NumCheckValid = !(generalParametersDisplayRules.IsBillingCode6Num && !Regex.IsMatch(firstBillingCodeInput.Value, "^(\\d{6})$"));
  37.             firstBillingCodeInput.Is8NumCheckValid = !(generalParametersDisplayRules.IsBillingCode8Num && !Regex.IsMatch(firstBillingCodeInput.Value, "^(\\d{4}\\-\\d{4})$"));
  38.  
  39.             var billingCodeRequiredAllCheck = true;
  40.  
  41.             if (generalParametersDisplayRules.IsBillingCodeRequiredAll)
  42.             {
  43.                 for (int i = 0; i < billingCodes.Count && i < allowedNumber; i++)
  44.                 {
  45.                     if (string.IsNullOrEmpty(billingCodes[i].Value))
  46.                     {
  47.                         billingCodeRequiredAllCheck = false;
  48.                     }
  49.                 }
  50.             }
  51.  
  52.             var billingCodesRequiredList = new[]
  53.             {
  54.                 generalParametersDisplayRules.IsBillingCode1Required,
  55.                 generalParametersDisplayRules.IsBillingCode2Required,
  56.                 generalParametersDisplayRules.IsBillingCode3Required,
  57.                 generalParametersDisplayRules.IsBillingCode4Required,
  58.                 generalParametersDisplayRules.IsBillingCode5Required,
  59.                 generalParametersDisplayRules.IsBillingCode6Required,
  60.                 generalParametersDisplayRules.IsBillingCode7Required
  61.             };
  62.  
  63.             for (int i = 0; i < billingCodesRequiredList.Length; i++)
  64.             {
  65.                 var currentNumber = i + 1;
  66.                 billingCodes[i].IsRequiredCheckValid = !(billingCodesRequiredList[i]
  67.                                                          && allowedNumber >= currentNumber
  68.                                                          && string.IsNullOrEmpty(billingCodes[i].Value))
  69.                                                          && !billingCodeChecked[i];
  70.  
  71.                 billingCodes[i].IsNumericCheckValid = !(generalParametersDisplayRules.IsBillingCodeNumeric
  72.                                                       && allowedNumber >= currentNumber
  73.                                                       && this.IsNotNumeric(electronicI9.BillingInfo.BillingCodeNum1));
  74.             }
  75.  
  76.             return new BillingCodesValidationResult
  77.             {
  78.                 IsRequiredAllCheckValid = billingCodeRequiredAllCheck,
  79.                 BillingCodes = billingCodes
  80.             };
  81.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement