Ejemplo n.º 1
0
        public WalletDrCrResponse InsertWalletTQDebit(string timestamp, long walletID, string coinName, decimal amount, long TrnRefNo, enServiceType serviceType, enWalletTrnType trnType, enWalletTranxOrderType enWalletTranx, enWalletLimitType enWalletLimit)
        {
            try
            {
                WalletMaster           Walletobj;
                string                 remarks = "";
                WalletTypeMaster       walletTypeMaster;
                WalletTransactionQueue objTQ;
                //long walletTypeID;
                WalletDrCrResponse resp = new WalletDrCrResponse();
                long owalletID, orgID;

                walletTypeMaster = _WalletTypeMasterRepository.GetSingle(e => e.WalletTypeName == coinName);
                if (walletTypeMaster == null)
                {
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidReq, ErrorCode = enErrorCode.InvalidCoinName
                    });
                }
                Walletobj = _commonRepository.GetById(walletID);
                //orgID = _walletRepository1.getOrgID();
                //if (orgID == 0)
                //{
                //    return new WalletDrCrResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.OrgIDNotFound, ErrorCode = enErrorCode.OrgIDNotFound };
                //}
                //Walletobj = _commonRepository.FindBy(e => e.WalletTypeID == Walletobj.WalletTypeID && e.UserID == orgID && e.IsDefaultWallet == 1 && e.Status == 1).FirstOrDefault();
                //if (Walletobj == null)
                //{
                //    //tqObj = InsertIntoWalletTransactionQueue(Guid.NewGuid().ToString(), orderType, amount, TrnRefNo, UTC_To_IST(), null, dWalletobj.Id, coinName, userID, timestamp, 2, EnResponseMessage.InvalidWallet);
                //    return new WalletDrCrResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidWallet, ErrorCode = enErrorCode.InvalidWallet };
                //}
                if (Walletobj.Status != 1 || Walletobj.IsValid == false)
                {
                    // insert with status=2 system failed
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.InvalidWallet, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);

                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidWallet, ErrorCode = enErrorCode.InvalidWallet, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }

                if (!CheckUserBalance(Walletobj.Id))
                {
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.BalMismatch, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidWallet, ErrorCode = enErrorCode.SettedBalanceMismatch, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                if (TrnRefNo == 0) // sell 13-10-2018
                {
                    // insert with status=2 system failed
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.InvalidTradeRefNo, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);

                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidTradeRefNo, ErrorCode = enErrorCode.InvalidTradeRefNo, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                if (amount <= 0)
                {
                    // insert with status=2 system failed
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.InvalidAmt, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);

                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidAmt, ErrorCode = enErrorCode.InvalidAmount, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                if (Walletobj.Balance < amount)
                {
                    // insert with status=2 system failed
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.InsufficantBal, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);

                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InsufficantBal, ErrorCode = enErrorCode.InsufficantBal, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                // ntrivedi 03-11-2018
                if (_commonWalletFunction.CheckShadowLimit(Walletobj.Id, amount) != enErrorCode.Success)
                {
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.ShadowLimitExceed, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.ShadowLimitExceed, ErrorCode = enErrorCode.ShadowBalanceExceed, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                //vsolanki 208-11-1
                var charge = GetServiceLimitChargeValue(enTrnType.Deposit, coinName);//for deposit
                if (charge.MaxAmount < amount && charge.MinAmount > amount)
                {
                    var msg1 = EnResponseMessage.ProcessTrn_AmountBetweenMinMaxMsg;
                    msg1  = msg1.Replace("@MIN", charge.MinAmount.ToString());
                    msg1  = msg1.Replace("@MAX", charge.MaxAmount.ToString());
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, msg1, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = msg1, ErrorCode = enErrorCode.ProcessTrn_AmountBetweenMinMax
                    });
                }

                int count = CheckTrnRefNo(TrnRefNo, enWalletTranx, trnType);
                if (count != 0)
                {
                    // insert with status=2 system failed
                    objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.AlredyExist, trnType);
                    objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);

                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.AlredyExist, ErrorCode = enErrorCode.AlredyExist, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                    });
                }
                // ntrivedi need to add condition for allowd wallet trntype
                // ntrivedi need to match transactionaccount
                // ntrivedi need to check limit (deposit , withdrawal , trading ) set by user
                objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Debit, amount, TrnRefNo, UTC_To_IST(), null, Walletobj.Id, coinName, Walletobj.UserID, timestamp, 0, "Inserted", trnType);
                objTQ = _walletRepository1.AddIntoWalletTransactionQueue(objTQ, 1);
                return(new WalletDrCrResponse {
                    ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.SuccessDebit, ErrorCode = enErrorCode.Success, TrnNo = objTQ.TrnNo, Status = objTQ.Status, StatusMsg = objTQ.StatusMsg
                });
            }
            catch (Exception ex)
            {
                //_log.LogError(ex, "Date: " + UTC_To_IST() + ",\nMethodName:" + System.Reflection.MethodBase.GetCurrentMethod().Name + "\nClassname=" + this.GetType().Name, LogLevel.Error);
                HelperForLog.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.GetType().Name, ex);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public WalletDrCrResponse DepositionWalletOperation(string timestamp, string address, string coinName, decimal amount, long TrnRefNo, enServiceType serviceType, enWalletTrnType trnType, enWalletTranxOrderType enWalletTranx, enWalletLimitType enWalletLimit, enTrnType routeTrnType, string Token = "")
        {
            try
            {
                WalletMaster           dWalletobj, cWalletObj;
                string                 DrRemarks = "", CrRemarks = "";
                WalletTypeMaster       walletTypeMaster;
                WalletTransactionQueue objTQDr, objTQCr;
                //long walletTypeID;
                WalletDrCrResponse resp = new WalletDrCrResponse();
                long owalletID, orgID;
                WalletTransactionOrder woObj;
                HelperForLog.WriteLogIntoFile("DepositionWalletOperation", "WalletService", "timestamp:" + timestamp + "," + "coinName:" + coinName + ",TrnRefNo=" + TrnRefNo.ToString() + ",address=" + address + ",amount=" + amount.ToString() + ",Token=" + Token);


                // moved inside InsertWalletTQDebit
                //walletTypeMaster = _WalletTypeMasterRepository.GetSingle(e => e.WalletTypeName == coinName);
                //if (walletTypeMaster == null)
                //{
                //    return new WalletDrCrResponse { ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidReq, ErrorCode = enErrorCode.InvalidCoinName };
                //}
                owalletID = GetWalletByAddress(address);
                if (owalletID == 0)
                {
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidAddress, ErrorCode = enErrorCode.InvalidAddress
                    });
                }
                cWalletObj = _commonRepository.GetById(owalletID);
                orgID      = _walletRepository1.getOrgID();
                if (orgID == 0)
                {
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.OrgIDNotFound, ErrorCode = enErrorCode.OrgIDNotFound
                    });
                }
                dWalletobj = _commonRepository.FindBy(e => e.WalletTypeID == cWalletObj.WalletTypeID && e.UserID == orgID && e.IsDefaultWallet == 1 && e.Status == 1).FirstOrDefault();
                if (dWalletobj == null)
                {
                    //tqObj = InsertIntoWalletTransactionQueue(Guid.NewGuid().ToString(), orderType, amount, TrnRefNo, UTC_To_IST(), null, dWalletobj.Id, coinName, userID, timestamp, 2, EnResponseMessage.InvalidWallet);
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidWallet, ErrorCode = enErrorCode.InvalidWallet
                    });
                }
                //ntrivedi 03-11-2018
                var charge = _commonWalletFunction.GetServiceLimitChargeValue(enTrnType.Deposit, coinName);
                if (charge.MaxAmount < amount && charge.MinAmount > amount)
                {
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.ProcessTrn_AmountBetweenMinMaxMsg, ErrorCode = enErrorCode.ProcessTrn_AmountBetweenMinMax
                    });
                }
                resp = InsertWalletTQDebit(timestamp, dWalletobj.Id, coinName, amount, TrnRefNo, serviceType, enWalletTrnType.Dr_Debit, enWalletTranx, enWalletLimit);
                if (resp.ReturnCode != 0 || resp.Status != enTransactionStatus.Initialize)
                {
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = resp.StatusMsg, ErrorCode = resp.ErrorCode
                    });
                }
                if (cWalletObj.Status != 1 || cWalletObj.IsValid == false)
                {
                    // insert with status=2 system failed
                    objTQCr = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Credit, amount, TrnRefNo, UTC_To_IST(), null, dWalletobj.Id, coinName, dWalletobj.UserID, timestamp, enTransactionStatus.SystemFail, EnResponseMessage.InvalidWallet, trnType);
                    objTQCr = _walletRepository1.AddIntoWalletTransactionQueue(objTQCr, 1);
                    return(new WalletDrCrResponse {
                        ReturnCode = enResponseCode.Fail, ReturnMsg = EnResponseMessage.InvalidWallet, ErrorCode = enErrorCode.InvalidWallet, TrnNo = objTQCr.TrnNo, Status = objTQCr.Status, StatusMsg = objTQCr.StatusMsg
                    });
                }

                objTQDr = _walletRepository1.GetTransactionQueue(resp.TrnNo);
                TrnAcBatch batchObj = _trnBatch.Add(new TrnAcBatch(UTC_To_IST()));
                DrRemarks = "Debit for Deposition TrnNo:" + TrnRefNo;
                WalletLedger       walletLedgerDr = GetWalletLedgerObj(dWalletobj.Id, cWalletObj.Id, amount, 0, enWalletTrnType.Dr_Debit, serviceType, objTQDr.TrnNo, DrRemarks, dWalletobj.Balance, 1);
                TransactionAccount tranxAccounDrt = GetTransactionAccount(dWalletobj.Id, 1, batchObj.Id, amount, 0, objTQDr.TrnNo, DrRemarks, 1);
                dWalletobj.DebitBalance(amount);
                objTQDr.Status    = enTransactionStatus.Success;
                objTQDr.StatusMsg = "Success";
                DrRemarks         = "Credit for Deposition TrnNo:" + TrnRefNo;
                objTQCr           = InsertIntoWalletTransactionQueue(Guid.NewGuid(), enWalletTranxOrderType.Credit, amount, TrnRefNo, UTC_To_IST(), null, cWalletObj.Id, coinName, cWalletObj.UserID, timestamp, 0, "Inserted", trnType);
                objTQCr           = _walletRepository1.AddIntoWalletTransactionQueue(objTQCr, 1);
                woObj             = InsertIntoWalletTransactionOrder(null, UTC_To_IST(), cWalletObj.Id, dWalletobj.Id, amount, coinName, objTQCr.TrnNo, objTQDr.TrnNo, 0, "Inserted");
                woObj             = _walletRepository1.AddIntoWalletTransactionOrder(woObj, 1);
                WalletLedger       walletLedgerCr = GetWalletLedgerObj(cWalletObj.Id, dWalletobj.Id, 0, amount, trnType, serviceType, objTQCr.TrnNo, DrRemarks, cWalletObj.Balance, 1);
                TransactionAccount tranxAccountCr = GetTransactionAccount(cWalletObj.Id, 1, batchObj.Id, 0, amount, objTQCr.TrnNo, DrRemarks, 1);
                cWalletObj.CreditBalance(amount);
                //var objTQ = InsertIntoWalletTransactionQueue(Guid.NewGuid(), orderType, TotalAmount, TrnRefNo, UTC_To_IST(), null, cWalletobj.Id, coinName, userID, timestamp, 1, "Updated");
                objTQCr.Status      = enTransactionStatus.Success;
                objTQCr.StatusMsg   = "Success";
                objTQCr.UpdatedDate = UTC_To_IST();
                woObj.Status        = enTransactionStatus.Success;
                woObj.StatusMsg     = "Deposition success for RefNo :" + TrnRefNo;
                woObj.UpdatedDate   = UTC_To_IST();
                objTQDr.SettedAmt   = amount;
                _walletRepository1.WalletCreditDebitwithTQ(walletLedgerDr, walletLedgerCr, tranxAccountCr, tranxAccounDrt, dWalletobj, cWalletObj, objTQCr, objTQDr, woObj);
                //ntrivedi temperory
                //vsolanki 2018-11-1---------------socket method   --------------------------
                WalletMasterResponse walletMasterObj = new WalletMasterResponse();
                walletMasterObj.AccWalletID   = cWalletObj.AccWalletID;
                walletMasterObj.Balance       = cWalletObj.Balance;
                walletMasterObj.WalletName    = cWalletObj.Walletname;
                walletMasterObj.PublicAddress = cWalletObj.PublicAddress;
                walletMasterObj.AccWalletID   = cWalletObj.AccWalletID;
                walletMasterObj.CoinName      = coinName;
                var msg = EnResponseMessage.CreditWalletMsg;
                msg = msg.Replace("#Coin#", coinName);
                msg = msg.Replace("#TrnType#", routeTrnType.ToString());
                msg = msg.Replace("#TrnNo#", TrnRefNo.ToString());
                try
                {
                    _signalRService.OnWalletBalChange(walletMasterObj, coinName, cWalletObj.UserID.ToString(), 2);
                    _signalRService.SendActivityNotification(msg, cWalletObj.UserID.ToString(), 2);
                }
                catch (Exception ex2)
                {
                    HelperForLog.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.GetType().Name, ex2);
                }
                // OnWalletBalChange(walletMasterObj, coinName,  Token);
                //-------------------------------


                //vsolanki 2018-11-1---------------socket method   --------------------------
                //WalletMasterResponse walletMasterObj1 = new WalletMasterResponse();
                //walletMasterObj.AccWalletID = cWalletObj.AccWalletID;
                //walletMasterObj.Balance = cWalletObj.Balance;
                //walletMasterObj.WalletName = cWalletObj.Walletname;
                //walletMasterObj.PublicAddress = cWalletObj.PublicAddress;
                //walletMasterObj.AccWalletID = cWalletObj.AccWalletID;
                //walletMasterObj.CoinName = coinName;
                //_signalRService.OnWalletBalChange(walletMasterObj1, coinName, Token);

                //OnWalletBalChange(walletMasterObj, coinName, Token);
                //-------------------------------



                //CreditWalletDrArryTrnID[] arryTrnID = new CreditWalletDrArryTrnID [1];
                //arryTrnID[0].Amount = amount;
                //arryTrnID[0].DrTrnRefNo = TrnRefNo;

                //resp = GetWalletCreditNew(coinName, timestamp, trnType, amount, cWalletObj.UserID, cWalletObj.AccWalletID,  arryTrnID, TrnRefNo,1,enWalletTranxOrderType.Credit,enServiceType.WalletService );
                return(new WalletDrCrResponse {
                    ReturnCode = enResponseCode.Success, ReturnMsg = EnResponseMessage.SuccessDebit, ErrorCode = enErrorCode.Success, TrnNo = resp.TrnNo, Status = resp.Status, StatusMsg = resp.StatusMsg
                });
            }
            catch (Exception ex)
            {
                //_log.LogError(ex, "Date: " + UTC_To_IST() + ",\nMethodName:" + System.Reflection.MethodBase.GetCurrentMethod().Name + "\nClassname=" + this.GetType().Name, LogLevel.Error);
                HelperForLog.WriteErrorLog(System.Reflection.MethodBase.GetCurrentMethod().Name, this.GetType().Name, ex);
                throw ex;
            }
        }