//Validates a BillPay instance public static void IsValid(NwbaContext _context, BillPay billPay, out Dictionary <string, string> errors) { errors = new Dictionary <string, string>(); Account account = _context.Accounts.Find(billPay.AccountNumber); Account destinationAccount = _context.Accounts.Find(billPay.PayeeID); if (destinationAccount == null) { errors.Add(nameof(billPay.PayeeID), "Destination account doesnt exist"); } else { if (account.AccountNumber == destinationAccount.AccountNumber) { errors.Add(nameof(billPay.PayeeID), "Cannot send to the same account"); } } if (billPay.Amount <= 0) { errors.Add(nameof(billPay.Amount), "Amount must be positive."); } if (billPay.ScheduleDate < DateTime.Now) { errors.Add(nameof(billPay.ScheduleDate), "Date cant be in the past"); } }
//validates a transaction instance public static void IsValid(NwbaContext _context, TransactionDto transaction, out Dictionary <string, string> errors) { errors = new Dictionary <string, string>(); Account account = _context.Accounts.Find(transaction.AccountNumber); Account destinationAccount = _context.Accounts.Find(transaction.DestinationAccountNumber); if (destinationAccount == null && transaction.Type == TransactionType.Transfer) { errors.Add(nameof(transaction.DestinationAccountNumber), "Destination account doesnt exist"); } else if (destinationAccount != null) { if (account.AccountNumber == destinationAccount.AccountNumber) { errors.Add(nameof(transaction.DestinationAccountNumber), "Cannot send to the same account"); } } if (transaction.Amount <= 0) { errors.Add(nameof(transaction.Amount), "Amount must be positive."); } if (transaction.Amount > account.Balance && transaction.Type != TransactionType.Deposit) { errors.Add(nameof(transaction.Amount), "Amount cannot be greater than your balance"); } }
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"); }
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(); }
//Attempts to log the user in public async Task <bool> LoginUser(NwbaContext _context, string _password, string loginID, Controller controller) { bool successfull = false; if (Status == LoginStatus.OPEN || (Status == LoginStatus.TEMP_LOCKED && LockedUntil <= DateTime.UtcNow)) { bool correctPassword = PBKDF2.Verify(PasswordHash, _password); //Creates a new login attempt and adds that to the database via the API LoginAttempt loginAttempt = new LoginAttempt { CustomerID = _context.Logins.Where(x => x.LoginID == loginID).FirstOrDefault().CustomerID, LoginTime = DateTime.Now, Successfull = correctPassword, }; var content = new StringContent(JsonConvert.SerializeObject(loginAttempt), Encoding.UTF8, "application/json"); await NwbaApi.InitializeClient().PostAsync("api/loginattempts", content); //If the login details are correct. log the user in. if (correctPassword) { // Logs in customer. controller.Response.Cookies.Append("LoggedIn", "", new CookieOptions() { Expires = DateTime.MaxValue }); controller.HttpContext.Session.SetInt32("LoggedIn", 1); controller.HttpContext.Session.SetInt32(nameof(CustomerID), CustomerID); controller.HttpContext.Session.SetString(nameof(Customer.Name), Customer.Name); //If the user was previously temporary locked, set to open. if (Status == LoginStatus.TEMP_LOCKED) { Status = LoginStatus.OPEN; } successfull = true; } else { controller.ModelState.AddModelError("Login", "Login Failed"); } } return(successfull); }
public override async Task <string> ExecuteAsync(NwbaContext _context) { var account = await _context.Accounts.FindAsync(AccountNumber); account.Balance = account.Balance + Amount; account.Transactions.Add( new Transaction { TransactionType = (char)Models.TransactionType.Deposit, Amount = Amount, Comment = Comment, TransactionTimeUtc = DateTime.UtcNow }); _context.SaveChanges(); return("true"); }
public void OneTimeProcess(BillPay paymentToProcess, NwbaContext _context) { if (paymentToProcess.ScheduleDate <= DateTime.Now) { var sourceAccount = _context.Accounts.FirstOrDefault(x => x.AccountNumber == paymentToProcess.AccountNumber); if (sourceAccount != null) { if (sourceAccount.AccountType.Equals(AccountType.Saving)) { minBalance = SAVINGS_MIN_ALLOWED_BALANCE; } else { minBalance = CHECK_MIN_ALLOWED_BALANCE; } if ((sourceAccount.Balance - paymentToProcess.Amount) > minBalance) { var transactionsOfCustomer = _context.Transactions.Where(x => x.AccountNumber == paymentToProcess.AccountNumber); if (transactionsOfCustomer != null) { //transaction var transaction = new Transaction(); transaction.TransactionType = TransactionType.BillPay; transaction.AccountNumber = paymentToProcess.AccountNumber; transaction.DestinationAccountNumber = paymentToProcess.PayeeID; transaction.Amount = paymentToProcess.Amount; transaction.TransactionTimeUtc = paymentToProcess.ScheduleDate; transaction.Comment = "Schedule Payment"; transaction.ModifyDate = DateTime.Now; _context.Transactions.Add(transaction); paymentToProcess.ModifyDate = DateTime.Now; paymentToProcess.BillPayStatus = BillPayStatus.Success; //reduce balance in source sourceAccount.Balance = sourceAccount.Balance - paymentToProcess.Amount; } } else { paymentToProcess.ModifyDate = DateTime.Now; paymentToProcess.BillPayStatus = BillPayStatus.Failed; } } } }
//Locks this user if 3 incorrect login attempts has been made public void UpdateLoginAttempts(NwbaContext _context, bool successfull) { List <LoginAttempt> loginAttempts = _context.LoginAttempts.OrderBy(x => x.LoginTime).ToList(); //check the last 3 login attempts. if all are failed, log user for X seconds bool shouldLock = true; for (int i = Math.Max(0, loginAttempts.Count() - 3); i < loginAttempts.Count(); ++i) { if (loginAttempts[i].Successfull == true) { shouldLock = false; } } if (shouldLock && Status != LoginStatus.TEMP_LOCKED) { LockedUntil = DateTime.UtcNow.AddSeconds(INACTIVE_TIMEOUT); Status = LoginStatus.TEMP_LOCKED; } }
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"); }
public AccountRepository(NwbaContext context) { _context = context; }
public TransactionRepository(NwbaContext context) { _context = context; }
public LoginRepository(NwbaContext context) { _context = context; }
public BillPayManager(NwbaContext context) { _context = context; }
public AddressRepository(NwbaContext context) { _context = context; }
public CustomerController(NwbaContext context) => _context = context;
public void AnnualProcess(BillPay paymentToProcess, NwbaContext _context) { // TODO: }
public void QuartelyProcess(BillPay paymentToProcess, NwbaContext _context) { // TODO: }
public abstract Task <string> ExecuteAsync(NwbaContext _context);
public BillPaysController(NwbaContext context) { _context = context; }
public AdminHomeController(NwbaContext context) => _context = context;
public BillPayController(NwbaContext context, IServiceScopeFactory serviceScopeFactory) { _context = context; _serviceScopeFactory = serviceScopeFactory; }
public ProfileController(NwbaContext context) => _context = context;
public TransactionController(NwbaContext context) => _context = context;
public BillPayController(NwbaContext context) => _context = context;
public AccountManager(NwbaContext context) { _context = context; }
public LoginController(NwbaContext context) => _context = context;
public AdminManager(NwbaContext context) { _context = context; }
public CustomersController(NwbaContext context) { _context = context; }
public ATMController(NwbaContext context) => _context = context;
public HomeController(ILogger <HomeController> logger, NwbaContext context) { _logger = logger; _context = context; }