public async Task Invoke(HttpContext context, IBWContext dbcontext) { var request = context.Request.Path.Value; String path = request.ToLower(); if (path.Contains("login") || path.Contains("api") || path == "/" || path.Contains("block") || path.Contains("expire")) { await _next.Invoke(context); } else if (context.Session.GetInt32(nameof(Customer.CustomerID)) != null) { Login login = dbcontext.Logins.Find(context.Session.GetInt32(nameof(Customer.CustomerID)).Value); if (login.Block) { context.Response.Redirect($"https://localhost:44310/Block/Block"); context.Session.Clear(); } else { await _next.Invoke(context); } } else { context.Response.Redirect($"https://localhost:44310/Expire/Expire"); } }
//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(); }
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(); }
//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(); }
//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(); }
//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; } } } } }
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(); } }
async void UnBlock(Object state) { var Context = new IBWContext(serviceProvider.CreateScope().ServiceProvider.GetRequiredService <DbContextOptions <IBWContext> >()); await UpdateBlock(Context); }
public LoginManager(IBWContext context) { _context = context; }
public CustomersController(IBWContext context) => _context = context;
public BillPaysController(IBWContext context) { _context = context; }
public ATMController(IBWContext context) => _context = context;
public CustomerManager(IBWContext context) { _context = context; }
//session key to restore user information. public AccountsController(IBWContext context) => _context = context;
public AccountManager(IBWContext context) { _context = context; }
public TransactionManager(IBWContext context) { _context = context; }
public BillPayManager(IBWContext context) { _context = context; }
public PayeeManager(IBWContext context) { _context = context; }
public LoginController(IBWContext context) { _context = context; }