public void ShouldReturnDigitsAsNumbers(string firstLineDigits, string secondLineDigits, string thirdLineDigits, string fourthLineDigits, int expectedAccountNumber) { var accountNumber = new AccountNumbers(); var result = accountNumber.ConvertToAccountNumbers(firstLineDigits, secondLineDigits, thirdLineDigits, fourthLineDigits); Assert.That(result, Is.EqualTo(expectedAccountNumber)); }
public static StreamWriter WriteToFile(string fileName2) { var accountNumbers = new AccountNumbers(); var theAccountNumbers = accountNumbers.GetAccountNumbers(); using (var writer = new StreamWriter(fileName2)) { foreach (int acountNumber in theAccountNumbers) { writer.WriteLine(acountNumber); } return(writer); } }
public JsonResult LodgeBatchOutwardCheque(IFormFile ExcelFile) { JsonResult Response = null; var OutwardCheques = new List <TblOutwardbankcheque>(); using (var Stream = new MemoryStream()) { ExcelFile.CopyTo(Stream); using (var package = new ExcelPackage(Stream)) { var Sheet = package.Workbook.Worksheets[0]; int RowCount = Sheet.Dimension.Rows; int ColumnCount = Sheet.Dimension.Columns; decimal?StampDutyAmount = GetStampDutyAmount(); Dictionary <string, string> .KeyCollection AccountNumbers; Dictionary <string, string> .KeyCollection BankLedgerIds; if (RowCount < 2 || ColumnCount != 7) { Response = Json( new { success = false, responseText = "Invalid document submitted. Please use the provided template." } ); } if (Response == null) { // Initialize API data AccountNumbers = GetApiData(ApiConstants.ChequeAccountEndpoint); BankLedgerIds = GetApiData(ApiConstants.ChartOfAccountEndpoint); TblOutwardbankcheque OutwardCheque; // loop through worksheet for (int Row = 2; Row <= RowCount; Row++) { try { OutwardCheque = new TblOutwardbankcheque { Datecreated = DateTime.Now, Referenceno = GetRandNo(7), Createdby = User.Identity.Name, // accept null until server //TODO: Operationid = , Accountno = Sheet.Cells[Row, 1].Value.ToString(), Amount = Convert.ToDecimal(Sheet.Cells[Row, 2].Value), Chequeno = Sheet.Cells[Row, 3].Value.ToString(), Chargestampduty = Convert.ToBoolean(Sheet.Cells[Row, 4].Value), Chequedate = Convert.ToDateTime(Sheet.Cells[Row, 5].Value.ToString()), Bankledgerid = Sheet.Cells[Row, 6].Value.ToString(), Narration = Sheet.Cells[Row, 7].Value?.ToString(), Approvalstatus = (int)ApprovalStatusEnum.INENTRYSTATE, Clearingoption = (int)ClearingOptionEnum.DEFAULT }; // Add/Remove ChargeStampDuty as appropriate if (OutwardCheque.Chargestampduty) { if (StampDutyAmount != null) { OutwardCheque.Chargestampamount = StampDutyAmount; } else { OutwardCheque.Chargestampduty = false; } } } catch (Exception ex) { if (ex is FormatException || ex is InvalidCastException || ex is OverflowException) { Response = Json( new { success = false, responseText = "Document contains invalid data format(s). " + "Please check that the data in columns 'Cheque Value Date', " + $"'Charge Stamp Duty' and 'Amount' on row {Row} are well formatted," + " then re-submit the document." } ); break; } else { throw; } } // check validity of Account No. and Bank Ledger ID if (!AccountNumbers.Contains(OutwardCheque.Accountno.Trim())) { Response = Json( new { success = false, responseText = $"Record in row {Row} contains an incorrect Account Number. " + "Please correct the value and then re-submit the document. Correct values are" + " available in the dropdown inside the information section." } ); break; } if (!BankLedgerIds.Contains(OutwardCheque.Bankledgerid.Trim())) { Response = Json( new { success = false, responseText = $"Record in row {Row} contains incorrect Bank Ledger ID. " + "Please correct the value and then re-submit the document. Correct values are" + " available in the dropdown inside the information section." } ); break; } OutwardCheques.Add(OutwardCheque); } ; } } } if (Response == null) { // begin attempt to save to database foreach (var Cheque in OutwardCheques) { RetailUnitOfWork.OutwardCheques.Add(Cheque); } RetailUnitOfWork.Commit(); Response = Json( new { success = true, responseText = "Excel upload completed successfully!" } ); } return(Response); }