Esempio n. 1
0
        //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");
            }
        }
Esempio n. 2
0
        //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");
            }
        }
Esempio n. 3
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");
        }
        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();
        }
Esempio n. 5
0
        //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);
        }
Esempio n. 6
0
        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");
        }
Esempio n. 7
0
        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;
                    }
                }
            }
        }
Esempio n. 8
0
        //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;
            }
        }
Esempio n. 9
0
        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");
        }
Esempio n. 10
0
 public AccountRepository(NwbaContext context)
 {
     _context = context;
 }
 public TransactionRepository(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 12
0
 public LoginRepository(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 13
0
 public BillPayManager(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 14
0
 public AddressRepository(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 15
0
 public CustomerController(NwbaContext context) => _context = context;
Esempio n. 16
0
 public void AnnualProcess(BillPay paymentToProcess, NwbaContext _context)
 {
     // TODO:
 }
Esempio n. 17
0
 public void QuartelyProcess(BillPay paymentToProcess, NwbaContext _context)
 {
     // TODO:
 }
Esempio n. 18
0
 public abstract Task <string> ExecuteAsync(NwbaContext _context);
 public BillPaysController(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 20
0
 public AdminHomeController(NwbaContext context) => _context = context;
Esempio n. 21
0
 public BillPayController(NwbaContext context, IServiceScopeFactory serviceScopeFactory)
 {
     _context             = context;
     _serviceScopeFactory = serviceScopeFactory;
 }
Esempio n. 22
0
 public ProfileController(NwbaContext context) => _context = context;
 public TransactionController(NwbaContext context) => _context = context;
Esempio n. 24
0
 public BillPayController(NwbaContext context) => _context = context;
Esempio n. 25
0
 public AccountManager(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 26
0
 public LoginController(NwbaContext context) => _context = context;
 public AdminManager(NwbaContext context)
 {
     _context = context;
 }
 public CustomersController(NwbaContext context)
 {
     _context = context;
 }
Esempio n. 29
0
 public ATMController(NwbaContext context) => _context = context;
Esempio n. 30
0
 public HomeController(ILogger <HomeController> logger, NwbaContext context)
 {
     _logger  = logger;
     _context = context;
 }