コード例 #1
0
        public async Task CreateBillPay(NwbaContext nwbaContext)
        {
            var billPay = new BillPay
            {
                AccountNumber = Account,
                PayeeID       = Payee,
                Amount        = Amount,
                ScheduleDate  = ScheduledDate.ToUniversalTime(),
                ModifyDate    = DateTime.UtcNow
            };

            if (Period.Equals("S"))
            {
                billPay.Period = Models.Period.S;
            }
            if (Period.Equals("M"))
            {
                billPay.Period = Models.Period.M;
            }
            if (Period.Equals("Q"))
            {
                billPay.Period = Models.Period.Q;
            }
            if (Period.Equals("Y"))
            {
                billPay.Period = Models.Period.Y;
            }

            nwbaContext.BillPays.Add(billPay);
            await nwbaContext.SaveChangesAsync();
        }
コード例 #2
0
        public override async Task <string> ExecuteAsync(NwbaContext _context)
        {
            decimal transferFee = 0;
            decimal miniBalance = 0;
            var     account     = await _context.Accounts.FindAsync(AccountNumber);

            if (account.Transactions.Count >= 4)
            {
                transferFee = fee;
            }
            if (account.AccountType == 'C')
            {
                miniBalance = 200;
            }
            if (account.Balance < Amount + transferFee + miniBalance)
            {
                return("Blance is not enough");
            }
            account.Balance = account.Balance - Amount - fee;
            account.Transactions.Add(
                new Transaction
            {
                TransactionType    = (char)Models.TransactionType.Withdraw,
                Amount             = Amount,
                Comment            = Comment,
                TransactionTimeUtc = DateTime.UtcNow
            });

            await _context.SaveChangesAsync();

            return("true");
        }
コード例 #3
0
        public async Task <IActionResult> EditBillPay(BillPayViewModel _billPay)
        {
            ModelState.Clear();

            //Validates the edited bill pay
            //Shows errors back if invalid
            Dictionary <string, string> errors = new Dictionary <string, string>();

            BillPay.IsValid(_context, _billPay.BillPay, out errors);

            if (errors.Count > 0)
            {
                foreach (KeyValuePair <string, string> entry in errors)
                {
                    ModelState.AddModelError(entry.Key, entry.Value);
                }
            }

            if (!ModelState.IsValid)
            {
                return(await EditBillPay(_billPay.BillPay.BillPayID));
            }

            //Updates the chosen bill
            BillPay billPay = await _context.BillPay.FindAsync(_billPay.BillPay.BillPayID);

            if (billPay == null)
            {
                return(await EditBillPay(_billPay.BillPay.BillPayID));
            }

            billPay.AccountNumber = _billPay.BillPay.AccountNumber;
            billPay.PayeeID       = _billPay.BillPay.PayeeID;
            billPay.Amount        = _billPay.BillPay.Amount;
            billPay.ScheduleDate  = _billPay.BillPay.ScheduleDate;
            billPay.Period        = _billPay.BillPay.Period;
            billPay.ModifyDate    = DateTime.UtcNow;

            //saves changes to the DB
            await _context.SaveChangesAsync();

            //goes back to the list view
            return(RedirectToAction("BillPayListView", "BillPay"));
        }
コード例 #4
0
        public async Task <IActionResult> Deposit(int id, decimal amount, string comment)
        {
            var account = await _context.Accounts.FindAsync(id);

            // If anything is wrong with deposit
            if (amount <= 0)
            {
                ModelState.AddModelError(nameof(amount), "Amount must be positive.");
            }
            if (amount.HasMoreThanTwoDecimalPlaces())
            {
                ModelState.AddModelError(nameof(amount), "Amount cannot have more than 2 decimal places.");
            }
            if (!ModelState.IsValid)
            {
                ViewBag.Amount = amount;
                return(View(account));
            }

            ATMMethods.Deposit(account, id, amount, comment);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
ファイル: TransferTransaction.cs プロジェクト: gyk99999/test
        public override async Task <string> ExecuteAsync(NwbaContext _context)
        {
            var fromAccount = await _context.Accounts.FindAsync(AccountNumber);

            var toAccount = await _context.Accounts.FindAsync(DestinationAccountNumber);

            decimal transferFee = 0;
            decimal miniBalance = 0;

            if (fromAccount.Transactions.Count >= 4)
            {
                transferFee = fee;
            }
            if (fromAccount.AccountType == 'C')
            {
                miniBalance = 200;
            }
            if (fromAccount.Balance < Amount + transferFee + miniBalance)
            {
                return("Blance is not enough");
            }
            fromAccount.Balance = fromAccount.Balance - Amount - fee;

            toAccount.Balance = toAccount.Balance + Amount;
            Transaction transaction = new Transaction
            {
                TransactionType          = (char)Models.TransactionType.Transfer,
                Amount                   = Amount,
                Comment                  = Comment,
                AccountNumber            = AccountNumber,
                DestinationAccountNumber = DestinationAccountNumber,
                TransactionTimeUtc       = DateTime.UtcNow
            };

            fromAccount.Transactions.Add(transaction);
            await _context.SaveChangesAsync();

            return("true");
        }
コード例 #6
0
        public async Task DoWork(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                executionCount++;

                _logger.LogInformation(
                    "Scoped Processing Service is working. Count: {Count}", executionCount);

                BusinessProcess businessProcess = new BusinessProcess();

                if (_context != null)
                {
                    // var x = _context.Accounts.Count();
                    var paymentsToProcess = _context.BillPays.Where(x => x.BillPayStatus == BillPayStatus.Waiting);
                    foreach (var paymentToProcess in paymentsToProcess)
                    {
                        switch (paymentToProcess.Period)
                        {
                        case "One Time":
                            businessProcess.OneTimeProcess(paymentToProcess, _context);
                            break;

                        case "Monthly":
                            // process this tx
                            businessProcess.OneTimeProcess(paymentToProcess, _context);
                            // schedule next tx
                            if (paymentToProcess.BillPayStatus == BillPayStatus.Success)
                            {
                                paymentToProcess.ScheduleDate.AddMonths(1);
                                paymentToProcess.BillPayStatus = BillPayStatus.Waiting;
                            }
                            break;

                        case "Quarterly":
                            // process this tx
                            businessProcess.OneTimeProcess(paymentToProcess, _context);
                            // schedule next tx
                            if (paymentToProcess.BillPayStatus == BillPayStatus.Success)
                            {
                                paymentToProcess.ScheduleDate.AddMonths(3);
                                paymentToProcess.BillPayStatus = BillPayStatus.Waiting;
                            }
                            break;

                        case "Annually":     //purposely schedule for 30s for demostration purposes
                            // process this tx
                            businessProcess.OneTimeProcess(paymentToProcess, _context);
                            // schedule next tx
                            if (paymentToProcess.BillPayStatus == BillPayStatus.Success)
                            {
                                paymentToProcess.ScheduleDate.AddMonths(12);
                                paymentToProcess.BillPayStatus = BillPayStatus.Waiting;
                            }
                            break;

                        default:

                            break;
                        }
                    }
                    await _context.SaveChangesAsync();
                }
                await Task.Delay(10000, stoppingToken);
            }
        }