public IActionResult addAgentfund([FromBody] FundVM fund) { var currentUser = HttpContext.User; Int32 userId = Convert.ToInt32(currentUser.Claims.FirstOrDefault(c => c.Type == "user_id").Value); AgentFund agentFund = new AgentFund(); try { if (fund != null) { //agentFund = _mapper.Map(fund, agentFund); agentFund.AgentId = fund.AgentId; agentFund.FundAmount = fund.FundAmount; agentFund.IsReceive = fund.IsReceive; agentFund.CreatedBy = userId; agentFund.Remark = "any"; agentFund.CreatedDate = DateTime.Now; _dbContext.AgentFund.Add(agentFund); _dbContext.SaveChanges(); } } catch (Exception ex) { } return(Ok()); }
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)); }