Пример #1
0
        //if bill pay is once delete it after transaction
        private async Task DeleteOnce(int id, IBWContext _context)
        {
            var billpay = _context.BillPays.Find(id);

            _context.Remove(billpay);
            await _context.SaveChangesAsync();
        }
Пример #2
0
        public async Task AddYearAsync(int id, IBWContext _context)
        {
            var billpay = _context.BillPays.Find(id);

            billpay.ScheduleDate = billpay.ScheduleDate.AddYears(1);
            _context.Add(billpay);
            _context.Update(billpay);
            await _context.SaveChangesAsync();
        }
Пример #3
0
        //if it is not once change the schedule date after transaction
        private async Task AddQuaterAsync(int id, IBWContext _context)
        {
            var billpay = _context.BillPays.Find(id);

            billpay.ScheduleDate = billpay.ScheduleDate.AddMonths(3);
            _context.Add(billpay);
            _context.Update(billpay);
            await _context.SaveChangesAsync();
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("BillPayID,AccountNumber,PayeeID,Amount,ScheduleDate,Period")] BillPay billPay)
        {
            if (MiscellaneousExtensionUtilities.HasMoreThanTwoDecimalPlaces(billPay.Amount))
            {
                ModelState.AddModelError(nameof(Transaction.Amount), "your should only have 2 decimal places in your amount.");
            }
            if (ModelState.IsValid)
            {
                billPay.ScheduleDate = TimeZoneInfo.ConvertTimeToUtc(billPay.ScheduleDate);
                _context.Add(billPay);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AccountNumber"] = new SelectList(_context.Accounts, "AccountNumber", "AccountNumber", billPay.AccountNumber);
            ViewData["PayeeID"]       = new SelectList(_context.Payees, "PayeeID", "PayeeName", billPay.PayeeID);
            return(View());
        }
Пример #5
0
        //update acount after the bill is paied
        public async Task UpDateAcc(int id, decimal amount, IBWContext _context)
        {
            var account = _context.Accounts.Find(id);

            account.Balance   -= (amount + .2m);
            account.ModifyDate = DateTime.UtcNow;
            _context.Add(account);
            _context.Update(account);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Login(string UserID, string password)
        {
            var login = await _context.Logins.Include(x => x.Customer).
                        FirstOrDefaultAsync(x => x.UserID == UserID);


            if (login.Block)
            {
                ModelState.AddModelError("LoginFailed", "Your account has been locked.");
                HttpContext.Session.SetInt32("Block", 0);
                return(View(new Login {
                    UserID = UserID
                }));
            }


            if (login == null || !PBKDF2.Verify(login.PasswordHash, password))
            {
                HttpContext.Session.SetInt32("Block", HttpContext.Session.GetInt32("Block").Value + 1);
                ModelState.AddModelError("LoginFailed", String.Format("Login failed, please try again. left attempt: {0}", 3 - HttpContext.Session.GetInt32("Block").Value));
                if (HttpContext.Session.GetInt32("Block").Value == 3)
                {
                    login.Block      = true;
                    login.ModifyDate = DateTime.UtcNow;
                    _context.Add(login);
                    _context.Update(login);
                    await _context.SaveChangesAsync();
                }
                return(View(new Login {
                    UserID = UserID
                }));
            }


            // Login customer.
            HttpContext.Session.SetInt32(nameof(Customer.CustomerID), login.CustomerID);
            HttpContext.Session.SetString(nameof(Customer.CustomerName), login.Customer.CustomerName);
            HttpContext.Session.SetString(nameof(Model.Login.UserID), UserID);

            return(RedirectToAction("Index", "ATM"));
        }
Пример #7
0
        //bill pay method
        async Task UpdateBillPay(IBWContext _context)
        {
            IList <BillPay> billpays = await _context.BillPays.ToListAsync();

            foreach (BillPay billpay in billpays)
            {
                // check date
                if (billpay.ScheduleDate.CompareTo(DateTime.UtcNow) <= 0 && !billpay.Block)
                {
                    Account     account     = _context.Accounts.Find(billpay.AccountNumber);
                    Transaction transaction = TransactionBuilder.BuildTransaction(billpay);
                    Transaction service     = TransactionBuilder.BuildTransaction(transaction);
                    // check if there is enough balance
                    if (TransferExtensionUtilities.checkBalance(transaction, account))
                    {
                        var transactions = _context.Transactions;
                        transactions.Add(transaction);
                        transactions.Add(service);
                        int id    = billpay.BillPayID;
                        int accId = billpay.AccountNumber;
                        await UpDateAcc(accId, billpay.Amount, _context);

                        await _context.SaveChangesAsync();

                        switch (billpay.Period)
                        {
                        case Period.M:
                            await AddMonthAsync(id, _context);

                            break;

                        case Period.Y:
                            await AddYearAsync(id, _context);

                            break;

                        case Period.Q:
                            await AddQuaterAsync(id, _context);

                            break;

                        case Period.O:
                            await DeleteOnce(id, _context);

                            break;
                        }
                    }
                }
            }
        }
Пример #8
0
        async Task UpdateBlock(IBWContext _context)
        {
            IList <Login> logins = await _context.Logins.ToListAsync();

            foreach (Login login in logins)
            {
                if (login.ModifyDate.AddSeconds(30).CompareTo(DateTime.UtcNow) <= 0)
                {
                    login.Block = false;
                    _context.Add(login);
                    _context.Update(login);
                }

                await _context.SaveChangesAsync();
            }
        }