//public IActionResult getAgentfund(Int32 userId, bool IsAgent = false)
        public IActionResult getAgentfund(bool IsAgent = false, Int32 AgentId = 0)
        {
            FundVMList objFundVMList = new FundVMList();

            try
            {
                //if(IsAgent)
                //{
                Int32 userId = Convert.ToInt32(User.Claims.FirstOrDefault(q => q.Type == "user_id").Value);
                //}

                List <AgentFund> lstagentFundDtl = new List <AgentFund>();
                if (IsAgent)
                {
                    lstagentFundDtl = _dbContext.AgentFund.Where(x => x.AgentId == userId).Include(x => x.Agent).Include(x => x.CreatedByNavigation).ToList();
                }
                else
                {
                    if (AgentId == 0)
                    {
                        lstagentFundDtl = _dbContext.AgentFund.Where(x => x.CreatedBy == userId).Include(x => x.Agent).Include(x => x.CreatedByNavigation).ToList();
                    }
                    else
                    {
                        lstagentFundDtl = _dbContext.AgentFund.Where(x => x.CreatedBy == userId && x.AgentId == AgentId).Include(x => x.Agent).Include(x => x.CreatedByNavigation).ToList();
                    }
                }

                if (lstagentFundDtl.Count > 0)
                {
                    List <FundVM> lstFundVM = new List <FundVM>();
                    lstFundVM = _mapper.Map <List <FundVM> >(lstagentFundDtl);
                    objFundVMList.lstFundVM = lstFundVM;
                    objFundVMList.AgentName = lstFundVM.First().AgnetName;
                }
            }
            catch (Exception ex)
            {
            }
            return(Ok(objFundVMList));
        }
        public IActionResult IsReceivefund(long agentfundId, bool isreceive)
        {
            AgentFund  objAgentFund  = new AgentFund();
            FundVMList objFundVMList = new FundVMList();

            try
            {
                var   currentUser    = HttpContext.User;
                Int32 loggedinuserId = Convert.ToInt32(currentUser.Claims.FirstOrDefault(c => c.Type == "user_id").Value);

                objAgentFund = _dbContext.AgentFund.FirstOrDefault(x => x.AgentFundId == agentfundId);
                if (objAgentFund != null)
                {
                    objAgentFund.IsReceive = true;
                    _dbContext.Entry(objAgentFund).State = EntityState.Modified;
                    _dbContext.SaveChanges();
                }

                if (objAgentFund.AgentFundId > 0)
                {
                    #region Top up walletamount in Logincredential
                    LoginCredentials objLoginCredentials = _dbContext.LoginCredentials.FirstOrDefault(x => x.UserId == objAgentFund.AgentId);
                    objLoginCredentials.WalletAmount          = Convert.ToDecimal(objLoginCredentials.WalletAmount) + objAgentFund.FundAmount;
                    _dbContext.Add(objLoginCredentials).State = EntityState.Modified;
                    _dbContext.SaveChanges();
                    #endregion


                    #region Add/Update balance bifurcation in AgentBalanceMst
                    AgentBalanceMst objAgentBalanceMst = _dbContext.AgentBalanceMst.FirstOrDefault(x => x.AgentId == loggedinuserId);
                    if (objAgentBalanceMst != null)
                    {
                        objAgentBalanceMst.Lb = objAgentBalanceMst.Lb + objAgentFund.FundAmount;
                        _dbContext.Add(objAgentBalanceMst).State = EntityState.Modified;
                        _dbContext.SaveChanges();
                    }
                    else
                    {
                        AgentBalanceMst addAgentBalanceMst = new AgentBalanceMst();
                        addAgentBalanceMst.Lb          = objAgentFund.FundAmount;
                        addAgentBalanceMst.AgentId     = loggedinuserId;
                        addAgentBalanceMst.CreatedDate = DateTime.Now;
                        addAgentBalanceMst.CreatedBy   = loggedinuserId;
                        addAgentBalanceMst.Lb          = objAgentFund.FundAmount;
                        _dbContext.AgentBalanceMst.Add(addAgentBalanceMst);
                        _dbContext.SaveChanges();
                    }
                    #endregion

                    List <AgentFund> lstagentFundDtl = _dbContext.AgentFund.Where(x => x.AgentId == agentfundId).Include(x => x.Agent).Include(x => x.CreatedByNavigation).ToList();
                    if (lstagentFundDtl.Count > 0)
                    {
                        List <FundVM> lstFundVM = new List <FundVM>();
                        lstFundVM = _mapper.Map <List <FundVM> >(lstagentFundDtl);
                        objFundVMList.lstFundVM = lstFundVM;
                        objFundVMList.AgentName = lstFundVM.First().AgnetName;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(Ok(objFundVMList));
        }