Ejemplo n.º 1
0
        public ShowBalanceDto GetDeposit(ShowBalanceDto model, string createdby)
        {
            //  Customer cust = _context.Customers.Where(b=>b.Id == customer.CustomerId)
            Customer cust = _context.Customers.SingleOrDefault(d => d.CustAccNumber == model.AccountNumber);

            Account acct = _context.Accounts.SingleOrDefault(d => d.AccountNumber == model.AccountNumber);

            if (cust.CustAccNumber != acct.AccountNumber)
            {
                throw new Exception("customer accont number does not match with account number");
            }


            if (cust.Cust_acc_type == "Savings")
            {
                if (model.Amount >= 1000)
                {
                    cust.Cust_balance  = cust.Cust_balance + Convert.ToDecimal(model.Amount);
                    cust.Streetaddress = cust.Streetaddress;
                    cust.Surname       = cust.Surname;
                    cust.Givenname     = cust.Givenname;

                    //update account table when trasaction is made
                    acct.Balance = cust.Cust_balance;
                    acct.CustId  = cust.Id;
                    // acct.AccountNumber = cust.CustAccNumber;

                    // Message = "";
                    // var requisitionURL = _config.GetSection("ExternalAPI:RequisitionURL").Value;

                    //var subject = "ALERT NOTIFICATION";

                    //var message = "</br><b> Dear </b>" + cust.Surname + " " + cust.Givenname;
                    //message += "</br><b> Your account: </b>" + cust.CustAccNumber;
                    //message += "</br><b> Credited with: #</b>" + model.Amount;
                    //message += "</br><b> Date of Transaction: #</b>" + cust.LastDateUpdated;
                    ////message += "</br>has been registered successful on Cyberspace E-procurement Portal.</br>";
                    ////message += "</br>Kindly, log in via " + requisitionURL + " and validate the required documents.";
                    //message += "</br>Regards";

                    //_emailSender.SendEmailAsync(cust.Emailaddress, subject, message, "");
                    Transaction tr = new Transaction();
                    tr.Amount        = model.Amount;
                    tr.Tr_Date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    tr.Tr_EmpType    = createdby;
                    tr.Attendant     = model.Attendant;
                    tr.ReferenceNo   = model.ReferenceNo;
                    tr.Depositor     = model.Depositor;
                    tr.Tr_AccName    = cust.Surname + " " + cust.Givenname;
                    tr.CustomerId    = cust.Id;
                    tr.Type          = "CashDeposit";
                    tr.AccountNumber = cust.CustAccNumber;
                    // tr.Tr_Branch = "Branch";

                    _context.Transactions.Add(tr);
                    _context.SaveChanges();

                    //  Accounts = customer.Accounts.Select(n => new CustomerAccountDto
                    if (acct != null)
                    {
                        var you = new ShowBalanceDto();
                        you.AccountNumber  = acct.AccountNumber;
                        you.Balance        = acct.Balance.Value;
                        you.FullName       = cust.Surname + " " + cust.Givenname;
                        you.RecipientEmail = cust.Emailaddress;
                        you.Amount         = model.Amount;
                        you.AccountNumber  = cust.CustAccNumber;
                        you.DateAndTransId = Convert.ToDateTime(tr.Tr_Date).ToString("yyyyMMdd") + tr.TransactionId.ToString("000");
                        you.Date           = Convert.ToString(cust.LastDateUpdated);
                        //you.Depositor = message;


                        return(you);
                    }

                    //fname + Now.ToString("_MMddyyyy_HHmmss")
                }
                else
                {
                    throw new Exception("Amount has to be higher that 1000Tk/Invalid");
                }
            }
            else if (cust.Cust_acc_type == "Loan")
            {
                Loan loan = _context.Loans.Where(x => x.AccountNumber == model.AccountNumber).FirstOrDefault();

                if (model.Amount >= 1000 && loan.IsActive == true)
                {
                    loan.Loan_Amount_Paid = loan.Loan_Amount_Paid + (model.Amount);
                    loan.Total_Paid      += (model.Amount);
                    //loan.Loan_Amount_Paid += Convert.ToDecimal(model.Amount);

                    Loan loantoUpdate = _context.Loans.SingleOrDefault(d => d.LoanId == loan.LoanId);
                    // Customer custToUpdate = _context.Customers.SingleOrDefault(d => d.CustAccNumber == model.AccountNumber);

                    loantoUpdate.AccountNumber = cust.CustAccNumber;
                    cust.Givenname             = cust.Givenname;
                    cust.Streetaddress         = cust.Streetaddress;
                    cust.Surname      = cust.Surname;
                    cust.Cust_balance = loan.Loan_Amount_Paid;

                    //update loan table when trasaction is made
                    acct.Balance = loan.Loan_Amount_Paid;
                    loan.CustId  = cust.Id;

                    //  return   _context.SaveChangesAsync();

                    // _context.Loans.Add(loan);

                    if (loan.Total_Paid == loan.AmountTo_Pay && loan.Deadline == DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"))
                    {
                        //loan.Status = "InActive";
                        loan.IsActive = false;
                        loantoUpdate.AccountNumber = cust.CustAccNumber;
                        cust.Givenname             = cust.Givenname;
                        cust.Streetaddress         = cust.Streetaddress;
                        cust.Surname = cust.Surname;
                        //loan.IsActive = false;
                    }

                    Transaction tr = new Transaction();
                    tr.Amount        = model.Amount;
                    tr.Tr_Date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    tr.Tr_EmpType    = createdby;
                    tr.Attendant     = model.Attendant;
                    tr.ReferenceNo   = model.ReferenceNo;
                    tr.Depositor     = model.Depositor;
                    tr.Tr_AccName    = cust.Surname + " " + cust.Givenname;
                    tr.CustomerId    = cust.Id;
                    tr.Type          = "Loan Deposit";
                    tr.AccountNumber = cust.CustAccNumber;
                    // tr.Tr_Branch = "Branch";

                    _context.Transactions.Add(tr);
                    _context.SaveChanges();


                    if (acct != null)
                    {
                        var you = new ShowBalanceDto();

                        you.AccountNumber  = acct.AccountNumber;
                        you.Balance        = acct.Balance.Value;
                        you.FullName       = cust.Surname + " " + cust.Givenname;
                        you.RecipientEmail = cust.Emailaddress;
                        you.Amount         = model.Amount;
                        you.AccountNumber  = cust.CustAccNumber;
                        you.DateAndTransId = Convert.ToDateTime(tr.Tr_Date).ToString("yyyyMMdd") + tr.TransactionId.ToString("000");
                        you.Date           = Convert.ToString(cust.LastDateUpdated);

                        //you.AccountNumber = acct.AccountNumber;
                        //you.Balance = acct.Balance.Value;
                        //you.DateAndTransId = Convert.ToDateTime(tr.Tr_Date).ToString("yyyyMMdd") + tr.TransactionId.ToString("000");
                        return(you);
                    }
                }
                else
                {
                    throw new Exception("Amount has to be higher that 1000Tk/Invalid");
                }
            }
            else
            {
                throw new Exception("Account Not Recognized");
            }

            return(model);
        }
Ejemplo n.º 2
0
        public ShowBalanceDto GetWildrawal(ShowBalanceDto model, string createdby)
        {
            Customer custw = _context.Customers.SingleOrDefault(c => c.CustAccNumber == model.AccountNumber);
            Account  acct  = _context.Accounts.SingleOrDefault(d => d.AccountNumber == model.AccountNumber);

            if (custw.CustAccNumber != acct.AccountNumber)
            {
                throw new Exception("customer accont number does not match with account number");
            }

            // Customer cust = _context.Customers.SingleOrDefault(d => d.Id == model.CustomerId);

            if (custw == null)
            {
                throw new Exception("Not exists with this Id");
            }


            if (custw.Cust_balance >= Convert.ToDecimal(model.Amount + 500) && model.Amount > 0 && custw.Cust_acc_type == "Savings")
            {
                custw.Cust_balance  = custw.Cust_balance - Convert.ToDecimal(model.Amount) /** DebitLiabilityAccountOperation*/;
                custw.Streetaddress = custw.Streetaddress;
                custw.Surname       = custw.Surname;
                custw.Givenname     = custw.Givenname;

                acct.Balance = custw.Cust_balance;
                acct.CustId  = custw.Id;

                Transaction tr = new Transaction();
                tr.Amount        = model.Amount;
                tr.Tr_Date       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                tr.Tr_EmpType    = createdby;
                tr.Attendant     = model.Attendant;
                tr.ReferenceNo   = model.ReferenceNo;
                tr.Depositor     = model.Depositor;
                tr.Tr_AccName    = custw.Surname + " " + custw.Givenname;
                tr.CustomerId    = custw.Id;
                tr.Type          = "CashWithdraw";
                tr.AccountNumber = custw.CustAccNumber;
                // tr.Tr_Branch = "Branch";

                _context.Transactions.Add(tr);
                _context.SaveChanges();


                if (acct != null)
                {
                    var you = new ShowBalanceDto();

                    you.AccountNumber         = acct.AccountNumber;
                    you.Balance               = acct.Balance.Value;
                    you.FullName              = custw.Surname + " " + custw.Givenname;
                    you.RecipientEmail        = custw.Emailaddress;
                    you.CustImageThumbnailUrl = custw.ImageThumbnailUrl;
                    you.Amount         = model.Amount;
                    you.AccountNumber  = custw.CustAccNumber;
                    you.DateAndTransId = Convert.ToDateTime(tr.Tr_Date).ToString("yyyyMMdd") + tr.TransactionId.ToString("000");
                    you.Date           = Convert.ToString(custw.LastDateUpdated);

                    //you.AccountNumber = acct.AccountNumber;
                    //you.Balance = acct.Balance.Value;
                    //you.CustImageThumbnailUrl = custw.ImageThumbnailUrl;
                    //you.DateAndTransId = Convert.ToDateTime(tr.Tr_Date).ToString("yyyyMMdd") + tr.TransactionId.ToString("000");
                    return(you);
                }
            }
            //else
            //{
            //    // ViewData["Message"] = "Amount has to be higher that 1000Tk/Invalid";
            //}


            else if (custw.Cust_acc_type == "Loan") // hangfire will do the wilthraw weekely
            {
                // LoanRepository lr = new LoanRepository();

                //  LInfo luser = lr.GetUser(ur.User_acc_no);


                //if (amount >= 1000 && luser.Status == "Active")
                //{
                //    luser.Loan_Amount_Paid += Convert.ToDouble(amount);
                //    lr.Update(luser, ur);

                //    if (luser.AmountTo_Pay == luser.Loan_Amount_Paid)
                //    {
                //        luser.Status = "InActive";
                //        lr.Update(luser, ur);
                //        ViewData["Message"] = "Loan Payment Successfull, Your Loan Account Has been Deactivated, Thank You, Sir. Come Again Soon!";
                //    }
                //}
                //else
                //{
                //    ViewData["Message"] = "Amount has to be higher that 1000Tk/Invalid";
                //}
            }
            else
            {
                //   ViewData["Message"] = "Account Not Recognized";
            }

            return(model);
        }