public bool IsUniqueName(string name)
 {
     if (glRepo.GetByName(name) == null)
     {
         return(true);
     }
     return(false);
 }
Example #2
0
        public bool NameIsUnique(string name)
        {
            bool isUnique = false;
            var  tName    = _db.GetByName(name);

            if (tName == null)
            {
                isUnique = true;
            }

            return(isUnique);
        }
Example #3
0
        public static Iso8583Message ProcessMessage(Iso8583Message msg, CbaProcessor.CbaListener.MessageSource msgSource)
        {
            //check the transaction type
            string transactionTypeCode = msg.Fields[MessageField.TRANSACTION_TYPE_FIELD].ToString().Substring(0, 2);
            long   accountNumber       = Convert.ToInt64(msg.Fields[MessageField.FROM_ACCOUNT_ID_FIELD].ToString()); //the From account number is the holders's account number
            var    customerAccount     = actRepo.GetByAccountNumber(accountNumber);

            decimal amount        = Convert.ToDecimal(msg[4].Value) / 100;  //converts to Naira
            decimal charge        = Convert.ToDecimal(msg[28].Value) / 100; //converts to Naira
            decimal processingFee = msg.Fields.Contains(31) ? Convert.ToDecimal(msg[31].Value) / 100 : 0;

            decimal totalCharges = charge + processingFee;
            decimal totalAmt     = amount + totalCharges;

            if (customerAccount == null && transactionTypeCode != "51")     //only for payment by deposit (51) do we not need From acct
            {
                msg.Fields.Add(MessageField.RESPONSE_FIELD, ResponseCode.NO_SAVINGS_ACCOUNT);
                return(msg);
            }

            #region REVERSAL
            if (msg.MessageTypeIdentifier == 420)   //Reversal Advice
            {
                msg.MessageTypeIdentifier = 430;    //Reversal Advice Response
                UtilityLogic.LogMessage("Processing a reversal message...");
                //check the transaction type
                if (transactionTypeCode.Equals(TransactionTypeCode.CASH_WITHDRAWAL))   //Reversing a withdrawal
                {
                    //We can only reverse a withdrawal, transfer or payment transaction for this scope

                    //if Withdrawal, debit the AtmGL and credit the customer account with the (amt+fee) in d msg
                    var atmGl = new GlAccountRepository().GetByName("ATMGL");
                    var withdrawalIncomeGl = glRepo.GetByName("WithdrawalIncomeGl");
                    if (atmGl == null || withdrawalIncomeGl == null)
                    {
                        msg.Fields.Add(39, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE);   //Issuer or switch inoperative.
                        return(msg);
                    }
                    CreditCustomer(customerAccount, totalAmt);
                    DebitGl(atmGl, amount);
                    DebitGl(withdrawalIncomeGl, totalCharges);

                    msg.Fields.Add(39, "00");       //successful transaction
                    UtilityLogic.LogMessage("Withdrawal Transaction reversed successfully");
                    return(msg);
                }
                else if (transactionTypeCode.Equals(TransactionTypeCode.PAYMENT_FROM_ACCOUNT))   //Reversing a (Payment from account)
                {
                    var onUsPaymentGl       = new GlAccountRepository().GetByName("OnUsPaymentGL");
                    var remoteOnUsPaymentGl = new GlAccountRepository().GetByName("RemoteOnUsPaymentGl");
                    var paymentIncomeGl     = glRepo.GetByName("PaymentIncomeGl");
                    if (onUsPaymentGl == null || remoteOnUsPaymentGl == null || paymentIncomeGl == null)
                    {
                        msg.Fields.Add(39, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE);   //Issuer or switch inoperative.
                        return(msg);
                    }

                    CreditCustomer(customerAccount, totalAmt);
                    if (msgSource == CbaProcessor.CbaListener.MessageSource.OnUs)
                    {
                        DebitGl(onUsPaymentGl, amount);
                    }
                    else
                    {
                        DebitGl(remoteOnUsPaymentGl, amount);
                    }

                    DebitGl(paymentIncomeGl, totalCharges);

                    msg.Fields.Add(39, "00");       //successful transaction
                    UtilityLogic.LogMessage("Payment reversed successfully");
                    return(msg);
                }
                else if (transactionTypeCode.Equals(TransactionTypeCode.INTRA_BANK_TRANSFER))   //Reversing a Transfer, 24 is assumed
                {
                    GlAccount intraBankTransferIncomeGl = glRepo.GetByName("IntraBankTransferIncomeGl");
                    if (intraBankTransferIncomeGl == null)
                    {
                        msg.Fields.Add(MessageField.RESPONSE_FIELD, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE);
                        return(msg);
                    }
                    var toAccountNumber = Convert.ToInt64(msg.Fields[MessageField.TO_ACCOUNT_ID_FIELD].Value);
                    var toAct           = new CustomerAccountRepository().GetByAccountNumber(toAccountNumber);
                    if (toAct == null)
                    {
                        msg.Fields.Add(MessageField.RESPONSE_FIELD, ResponseCode.NO_SAVINGS_ACCOUNT);
                        return(msg);
                    }
                    if (!(new CustomerAccountLogic().CustomerAccountHasSufficientBalance(toAct, totalAmt))) //insufficient balance
                    {
                        msg.Fields.Add(39, "51");                                                           //insufficient funds (in the ATM)
                        return(msg);
                    }

                    DebitCustomer(toAct, amount);
                    CreditCustomer(customerAccount, totalAmt);
                    DebitGl(intraBankTransferIncomeGl, totalCharges);

                    msg.Fields.Add(39, ResponseCode.SUCCESS);       //successful transaction
                    UtilityLogic.LogMessage("Transfer reversed successfully");
                    return(msg);
                }
            }
            #endregion

            else if (msg.MessageTypeIdentifier == 200)   //Transaction Request
            {
                msg.MessageTypeIdentifier = 210;
                #region BALANCE ENQUIRY
                //if balance enquiry, get the account number and return the balance
                if (transactionTypeCode.Equals(TransactionTypeCode.BALANCE_ENQUIRY))       //BALANCE ENQUIRY
                {
                    var feeIncomeGl = glRepo.GetByName("GeneralRemoteTransactionIncomeGl");
                    if (feeIncomeGl == null)
                    {
                        msg.Fields.Add(MessageField.RESPONSE_FIELD, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE);
                        return(msg);
                    }
                    ProcessBalanceEnquiry(msg, customerAccount, totalCharges, feeIncomeGl);
                    return(msg);
                }
                #endregion

                #region CASH WITHDRAWAL
                else if (transactionTypeCode.Equals(TransactionTypeCode.CASH_WITHDRAWAL))      //Cash Withdrawal
                {
                    return(ProcessCashWithrawal(msg, customerAccount, amount, charge, totalCharges, totalAmt));
                }
                #endregion Withdrawal

                #region PAYMENT FROM ACCOUNT
                else if (transactionTypeCode.Equals(TransactionTypeCode.PAYMENT_FROM_ACCOUNT))      //payment from account
                {
                    return(ProcessPaymentFromAccount(msg, msgSource, customerAccount, amount, totalCharges, totalAmt));
                }
                #endregion

                #region PAYMENT BY DEPOSIT
                else if (transactionTypeCode.Equals(TransactionTypeCode.PAYMENT_BY_DEPOSIT))      //PAYMENT BY DEPOSIT
                {
                    return(ProcessPaymentByDeposit(msg, msgSource, amount));
                }
                #endregion

                #region INTRA-BANK TRANSFER
                else if (transactionTypeCode.Equals(TransactionTypeCode.INTRA_BANK_TRANSFER))      //Intra-bank Transfer, 24 is just assumed
                {
                    return(ProcessIntraBankTransfer(msg, customerAccount, amount, totalCharges, totalAmt));
                }
                #endregion Intra-Bank Transfer
            }//End else-if

            //if we got this far, the transaction is invalid
            msg.Fields.Add(39, ResponseCode.INVALID_TRANSACTION);       //INVALID TRANSACTION
            return(msg);
        }