Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AssignLoan([FromForm] LoanRequestVM loanrequest)
        {
            List <CustomerLoanDocumentDtl> lstLoanDocument = new List <CustomerLoanDocumentDtl>();
            string folderName  = "CustomerDoc";
            var    currentUser = HttpContext.User;
            Int32  userId      = Convert.ToInt32(currentUser.Claims.FirstOrDefault(c => c.Type == "user_id").Value);

            try
            {
                CustomerLoan objCustomerLoan = new CustomerLoan();
                var          loan            = JsonConvert.DeserializeObject <LoadDetailVM>(loanrequest.loandetail);
                if (loan != null)
                {
                    objCustomerLoan           = _mapper.Map <CustomerLoan>(loan);
                    objCustomerLoan.CreatedBy = userId;
                    objCustomerLoan.AgentId   = userId;

                    objCustomerLoan.CreatedDate = DateTime.Now;
                    _context.CustomerLoan.Add(objCustomerLoan);
                    _context.SaveChanges();

                    #region CustomerLoanTxn

                    if (loan.lsttenure != null && loan.lsttenure.Count > 0)
                    {
                        if (objCustomerLoan.CustomerLoanId > 0)
                        {
                            List <CustomerLoanTxn> lstCustomerLoanTxn = new List <CustomerLoanTxn>();
                            lstCustomerLoanTxn = _mapper.Map <List <CustomerLoanTxn> >(loan.lsttenure);
                            foreach (var tenure in lstCustomerLoanTxn)
                            {
                                tenure.CreatedBy      = userId;
                                tenure.CreatedDate    = DateTime.Now;
                                tenure.CustomerLoanId = objCustomerLoan.CustomerLoanId;
                                _context.CustomerLoanTxn.Add(tenure);
                                _context.SaveChanges();
                            }
                        }
                    }

                    #endregion


                    #region AgentBalanceMst

                    AgentBalanceMst objAgentBalanceMst = _context.AgentBalanceMst.FirstOrDefault(x => x.AgentId == userId);
                    if (objAgentBalanceMst != null)
                    {
                        objAgentBalanceMst.Lb                    = objAgentBalanceMst.Lb - loan.LoanAmount;
                        objAgentBalanceMst.UpdatedBy             = userId;
                        objAgentBalanceMst.UpdatedDate           = DateTime.Now;
                        _context.Entry(objAgentBalanceMst).State = EntityState.Modified;
                        _context.SaveChanges();
                    }

                    #endregion

                    #region Upload Customer Loan Doc

                    if (loanrequest.uploadDoc != null)
                    {
                        foreach (var file in loanrequest.uploadDoc)
                        {
                            CustomerLoanDocumentDtl docDtl = new CustomerLoanDocumentDtl();
                            if (file.filedata == null && !string.IsNullOrEmpty(file.Filename))
                            {
                                //return BadRequest("Empty File");
                                docDtl.CustomerLoanId = objCustomerLoan.CustomerLoanId;
                                docDtl.DocumentTypeId = file.DocType;
                                docDtl.FileName       = file.Filename;
                                docDtl.UploadedDate   = DateTime.Now;
                                docDtl.UploadedBy     = userId;
                                lstLoanDocument.Add(docDtl);
                            }
                            else if (file.filedata != null)
                            {
                                //if (file.Length > 2 * 1024 * 1024) return BadRequest("Max file size exceeded.");
                                string webRootPath     = _hostingEnvironment.WebRootPath;
                                string uploadFilesPath = Path.Combine(webRootPath, folderName);
                                if (!Directory.Exists(uploadFilesPath))
                                {
                                    Directory.CreateDirectory(uploadFilesPath);
                                }

                                var fileName = Path.GetFileNameWithoutExtension(file.filedata.FileName) + "-" + Guid.NewGuid().ToString() + Path.GetExtension(file.filedata.FileName);
                                var filePath = Path.Combine(uploadFilesPath, fileName);
                                using (var stream = new FileStream(filePath, FileMode.Create))
                                {
                                    await file.filedata.CopyToAsync(stream);
                                }

                                docDtl.CustomerLoanId = objCustomerLoan.CustomerLoanId;
                                docDtl.DocumentTypeId = file.DocType;
                                docDtl.FileName       = fileName;
                                docDtl.UploadedDate   = DateTime.Now;
                                docDtl.UploadedBy     = userId;
                                lstLoanDocument.Add(docDtl);
                            }
                            else
                            {
                                break;
                            }
                        }
                        _context.CustomerLoanDocumentDtl.AddRange(lstLoanDocument);
                        _context.SaveChanges();
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.ExpectationFailed));
            }
            return(Ok(new { success = true }));
        }