Beispiel #1
0
        // Update transaction table
        private void UpdateTransactionDetails <T>(T ShopkeeperToCustomer)
        {
            var currentShopkeeperAccountNumber = Convert.ToInt64(ShopkeeperToCustomer.GetType().GetProperty("ShopKeeperAccountNumber").GetValue(ShopkeeperToCustomer, null));
            var terminalIMEINumber             = Convert.ToString(ShopkeeperToCustomer.GetType().GetProperty("IMEINumber").GetValue(ShopkeeperToCustomer, null));

            var currentCustomerNFCTagID = long.Parse(ShopkeeperToCustomer.GetType().GetProperty("NFCTagID").GetValue(ShopkeeperToCustomer, null).ToString());

            // Get current customer details
            var currentCustomerDetails = _changerMintsUOW.Repository <CustomerDetail>().Query().Filter(q => q.NFCTagID ==
                                                                                                       currentCustomerNFCTagID).Get().FirstOrDefault();

            var currentAmount = Convert.ToDecimal(ShopkeeperToCustomer.GetType().GetProperty("Amount").GetValue(ShopkeeperToCustomer, null));

            // Update the transaction table for Shopkeeper & Customer
            var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                     currentShopkeeperAccountNumber).Get().FirstOrDefault();
            var getCustomerAccountDetails = _changerMintsUOW.Repository <CustomerAccountDetail>().Query().Filter(q => q.CustomerAccountNumber ==
                                                                                                                 currentCustomerDetails.CustomerAccountNumber).Get().FirstOrDefault();

            var transactionID = GenerateTransactionID();
            // Update the transaction table for Shopkeeper
            var shopKeeperTransactionDetail = new ShopKeeperTransactionDetail()
            {
                ShopKeeperAccountNumber = getShopkeeperAccountDetails.ShopKeeperAccountNumber, SenderBalance = getShopkeeperAccountDetails.SenderBalance,
                ReceiverBalance         = getShopkeeperAccountDetails.ReceiverBalance, ReceivedFrom = 0, PaidTo = getCustomerAccountDetails.CustomerAccountNumber,
                AmountTransfered        = currentAmount,
                TransactionDate         = DateTime.Now,
                TransactionStatus       = 1001,
                TerminalIMEINumber      = terminalIMEINumber,
                TransactionID           = transactionID
            };

            _changerMintsUOW.Repository <ShopKeeperTransactionDetail>().Insert(shopKeeperTransactionDetail);

            // Update the transaction table for Customer
            var customerTransactionDetail = new CustomerTransactionDetail()
            {
                CustomerAccountNumber = getCustomerAccountDetails.CustomerAccountNumber, Balance = getCustomerAccountDetails.Balance,
                ReceivedFrom          = getShopkeeperAccountDetails.ShopKeeperAccountNumber, PaidTo = 0, AmountTransfered = currentAmount,
                TransactionDate       = DateTime.Now, TransactionStatus = 1001,
                TerminalIMEINumber    = terminalIMEINumber,
                TransactionID         = transactionID
            };

            _changerMintsUOW.Repository <CustomerTransactionDetail>().Insert(customerTransactionDetail);

            _changerMintsUOW.Save();
        }
Beispiel #2
0
        // Receiver balance to sender balance transaction service
        public InterTransactionResponse ShopKeeperToShopKeeperTransaction(ShopKeeperReceiverToSenderTransaction ShopkeeperToShopkeeper)
        {
            _interTransactionResponse = new InterTransactionResponse();

            try {
                var messageCreators = new List <ModelResponses <InterTransactionResponse, ChangerValidations> > {
                    // Check if the Shopkeeper Account is of Valid length
                    new ModelResponses <InterTransactionResponse, ChangerValidations>(model => model.IsShopKeeperAccountValid(
                                                                                          ShopkeeperToShopkeeper.ShopKeeperAccountNumber), 1101),
                    // Check if the Amount is of >0
                    new ModelResponses <InterTransactionResponse, ChangerValidations>(model => model.IsAmountValid(
                                                                                          ShopkeeperToShopkeeper.Amount), 1401),
                };

                ModelResponses <InterTransactionResponse, ChangerValidations> errorCreator = null;
                if (!ChangerValidations.GetInputParametersStatus <InterTransactionResponse, ChangerValidations>(messageCreators, out errorCreator))
                {
                    return(errorCreator.FillErrorDTO <InterTransactionResponse>());
                }

                // Get current shopkeeper account details
                var currentShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();

                if (currentShopkeeperAccountDetails == null)
                {
                    _interTransactionResponse.ErrorNumber  = 1107;
                    _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];

                    return(_interTransactionResponse);
                }

                if (currentShopkeeperAccountDetails.ReceiverBalance > ShopkeeperToShopkeeper.Amount &&
                    currentShopkeeperAccountDetails.ReceiverBalance > 0)
                {
                    // Start Transaction
                    decimal TransferableAmountToShopkeeper = TRANSFERABLE_PERCENTAGE_AFTER_COMMISION * ShopkeeperToShopkeeper.Amount;
                    decimal TransferableAmountToChanger    = COMMISSION_TO_CHANGER * ShopkeeperToShopkeeper.Amount;

                    currentShopkeeperAccountDetails.ReceiverBalance -= ShopkeeperToShopkeeper.Amount;
                    currentShopkeeperAccountDetails.SenderBalance   += TransferableAmountToShopkeeper;
                    _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Update(currentShopkeeperAccountDetails);
                    _changerMintsUOW.Save();

                    // Update the Transaction details
                    var getShopkeeperAccountDetails = _changerMintsUOW.Repository <ShopKeeperAccountDetail>().Query().Filter(q => q.ShopKeeperAccountNumber ==
                                                                                                                             ShopkeeperToShopkeeper.ShopKeeperAccountNumber).Get().FirstOrDefault();

                    // Update the transaction table for Shopkeeper
                    var shopKeeperTransactionDetail = new ShopKeeperTransactionDetail()
                    {
                        ShopKeeperAccountNumber = getShopkeeperAccountDetails.ShopKeeperAccountNumber, SenderBalance = getShopkeeperAccountDetails.SenderBalance,
                        ReceiverBalance         = getShopkeeperAccountDetails.ReceiverBalance, ReceivedFrom = 0, PaidTo = getShopkeeperAccountDetails.ShopKeeperAccountNumber,
                        AmountTransfered        = ShopkeeperToShopkeeper.Amount, TransactionDate = DateTime.Now, TransactionStatus = 1001, TerminalIMEINumber = ShopkeeperToShopkeeper.TerminalIMEINumber,
                        TransactionID           = GenerateTransactionID()
                    };
                    _changerMintsUOW.Repository <ShopKeeperTransactionDetail>().Insert(shopKeeperTransactionDetail);
                    _changerMintsUOW.Save();

                    // success message
                    _interTransactionResponse.ErrorNumber     = 1302;
                    _interTransactionResponse.ErrorMessage    = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
                    _interTransactionResponse.SenderBalance   = Convert.ToDecimal(currentShopkeeperAccountDetails.SenderBalance);
                    _interTransactionResponse.ReceiverBalance = Convert.ToDecimal(currentShopkeeperAccountDetails.ReceiverBalance);
                }
                else
                {
                    _interTransactionResponse.ErrorNumber = 1301;
                }
                _interTransactionResponse.ErrorMessage = ConfigurationManager.AppSettings[_interTransactionResponse.ErrorNumber.ToString()];
            } catch (Exception e) {
                throw e;
            }
            return(_interTransactionResponse);
        }