public static void CreditTransactionOld(Models.Input <CreditTransactions> obj)
        {
            PayitMerchantsnWalletsEntities db = new PayitMerchantsnWalletsEntities();

            var CustDeatils = (from a in db.Customers
                               join b in db.CustomerDevices on a.ID equals b.CustomerID
                               join c in db.CustomerWallets on a.ID equals c.CustomerID
                               where a.MobileNo == obj.input.mobile && b.DeviceUDID == obj.param.deviceuniqueid
                               select c.ID).FirstOrDefault();

            if (CustDeatils != null)
            {
                CustomerWalletTransaction CusWL = new CustomerWalletTransaction();

                CusWL.CustomerWalletID = CustDeatils;
                CusWL.Amount           = string.IsNullOrEmpty(obj.input.amount) ? 0 : Convert.ToDouble(obj.input.amount);
                CusWL.ThirdPartyID     = 1;
                CusWL.Reference        = obj.input.paymentref;
                CusWL.TransactionType  = "CREDIT";
                CusWL.TransactionDate  = DateTime.Now;
                CusWL.Status           = true;

                db.CustomerWalletTransactions.Add(CusWL);
                db.SaveChanges();
                var walletTranID = CusWL.ID;
                CustomerWalletTransactionsCredit CusWC = new CustomerWalletTransactionsCredit();

                CusWC.WalletTransactionID    = walletTranID;
                CusWC.CreditChannel          = "OneInWallet";
                CusWC.CreditChannelReference = obj.input.paymentref;
                CusWC.Status          = true;
                CusWC.TransactionDate = DateTime.Now;
                CusWC.Description     = "CAPTURED";

                db.CustomerWalletTransactionsCredits.Add(CusWC);
                db.SaveChanges();
            }
        }
        //public MerchantDTO MerchantTransaction(Models.Input<QRPayRequest> obj, string refer, string code)
        //{
        //    PayitMerchantsnWalletsEntities db = new PayitMerchantsnWalletsEntities();
        //    Merchant merchant = new Merchant();
        //    MerchantDTO dto = new MerchantDTO();
        //    MerchantOrder order = new MerchantOrder();
        //    MerchantTransaction merchantTran = new MerchantTransaction();
        //    CustomerWalletTransaction CusWL = new CustomerWalletTransaction();
        //    var mDetails = (from a in db.Merchants
        //                    where a.Name == obj.input.QR.name && a.Code == code
        //                    select a).FirstOrDefault();
        //    try
        //    {
        //        if (mDetails != null)
        //        {
        //            merchantTran.Amount = string.IsNullOrEmpty(obj.input.amount) ? 0 : Convert.ToDouble(obj.input.amount);
        //            merchantTran.MerchantID = mDetails.ID;
        //            merchantTran.Reference = refer;
        //            merchantTran.Status = true;
        //            merchantTran.TransactionDate = DateTime.Now;
        //            db.MerchantTransactions.Add(merchantTran);
        //            db.SaveChanges();

        //            order.Amount = merchantTran.Amount;
        //            order.MerchantUserID = Convert.ToInt32(obj.input.QR.merchantuserid);
        //            order.Description = "QRPAYMENT";
        //            order.isPaid = true;
        //            //order.MerchantUserID =
        //            order.MobileNo = mDetails.PhoneNo;
        //            order.PaymentReference = merchantTran.Reference;
        //            order.ProcessDate = DateTime.Now;
        //            order.Reference = merchantTran.Reference;
        //            order.Status = true;
        //            order.StatusDescription = "WalletPay";
        //            order.TranDate = DateTime.Now;
        //            db.MerchantOrders.Add(order);
        //            db.SaveChanges();

        //            merchant.Amount = mDetails.Amount + merchantTran.Amount;
        //            db.SaveChanges();
        //            dto.Amount = mDetails.Amount.ToString();
        //            dto.Code = mDetails.Code.ToString();
        //            dto.CountryCode = mDetails.CountryCode;
        //            dto.Name = mDetails.Name;
        //        }
        //    }
        //    catch
        //    {
        //        dto.Name = "";
        //        dto.Amount = "";
        //        dto.Code = "";
        //        dto.CountryCode = "";
        //    }
        //    return dto;
        //}

        public MerchantDTO MerchantTransaction(Models.Input <QROrderRequest> obj, string refer, string code)
        {
            PayitMerchantsnWalletsEntities db = new PayitMerchantsnWalletsEntities();
            Merchant      merchant            = new Merchant();
            MerchantDTO   dto   = new MerchantDTO();
            MerchantOrder order = new MerchantOrder();
            //QROrderItem qrord = new QROrderItem();
            QROrderRequest            qrord        = new QROrderRequest();
            MerchantOrderItem         ordItem      = new MerchantOrderItem();
            MerchantTransaction       merchantTran = new MerchantTransaction();
            CustomerWalletTransaction CusWL        = new CustomerWalletTransaction();
            var mDetails = (from a in db.Merchants
                            where a.Name == obj.input.QR.name && a.Code == code
                            select a).FirstOrDefault();

            try
            {
                if (mDetails != null)
                {
                    merchantTran.Amount          = string.IsNullOrEmpty(obj.input.amount) ? 0 : Convert.ToDouble(obj.input.amount);
                    merchantTran.MerchantID      = mDetails.ID;
                    merchantTran.Reference       = refer;
                    merchantTran.Status          = true;
                    merchantTran.TransactionDate = DateTime.Now;
                    db.MerchantTransactions.Add(merchantTran);
                    db.SaveChanges();

                    order.Amount            = merchantTran.Amount;
                    order.Description       = "QRPAYMENT";
                    order.isPaid            = true;
                    order.MerchantUserID    = Convert.ToInt32(obj.input.QR.merchantuserid);
                    order.MobileNo          = mDetails.PhoneNo;
                    order.PaymentReference  = merchantTran.Reference;
                    order.ProcessDate       = DateTime.Now;
                    order.Reference         = merchantTran.Reference;
                    order.Status            = true;
                    order.StatusDescription = "WalletPay";
                    order.TranDate          = DateTime.Now;
                    db.MerchantOrders.Add(order);
                    db.SaveChanges();

                    foreach (var row in obj.input.QR.orderitems)
                    {
                        double total = Convert.ToInt32(row.price) * Convert.ToInt32(row.quantity);

                        ordItem.MerchantOrderID = order.ID;
                        ordItem.MerchantItemID  = Convert.ToInt32(row.itemid);
                        ordItem.Quantity        = Convert.ToInt32(row.quantity);
                        ordItem.UnitPrice       = Convert.ToDouble(row.price);
                        ordItem.ItemAmount      = total;
                        ordItem.CreatedDate     = DateTime.Now;
                        ordItem.Status          = true;
                        db.MerchantOrderItems.Add(ordItem);
                        db.SaveChanges();
                    }
                    merchant.Amount = mDetails.Amount + merchantTran.Amount;
                    db.SaveChanges();
                    dto.Amount      = mDetails.Amount.ToString();
                    dto.Code        = mDetails.Code.ToString();
                    dto.CountryCode = mDetails.CountryCode;
                    dto.Name        = mDetails.Name;
                }
            }
            catch
            {
                dto.Name        = "";
                dto.Amount      = "";
                dto.Code        = "";
                dto.CountryCode = "";
            }
            return(dto);
        }