Пример #1
0
        public async Task <List <Accounts> > GetChecking(Project1Context c, string userId)
        {
            var             _repo = new AccountsRepo(c);
            List <Accounts> all   = await _repo.GetAll(userId);

            return(all.Where(a => a.Type.Id == _repo.GetTypeId("Checking")).ToList());
        }
Пример #2
0
 public AccountsController(Project1Context context, UserManager <YABUser> userManager, ILogger <AccountsController> logger)
 {
     _userManager = userManager;
     _logger      = logger;
     _context     = context;
     _arepo       = new AccountsRepo(context);     //TODO Remove
     _trepo       = new TransactionsRepo(context); //TODO Remove
     _bl          = new BL(context);
 }
Пример #3
0
        public string AddBankAccount(NewBankAccountModel newBankAccountModel)
        {
            var accountRepo   = new AccountsRepo();
            var accountNumber = BankAccountNumberGenerator.GetUniqueAccountNumber();

            newBankAccountModel.AccountNumber = accountNumber;
            newBankAccountModel.Iban          = IbanGenerator.GenerateIban(accountNumber);
            newBankAccountModel.Expired       = false;

            var withdrawnAccount = accountRepo.GetWhitdrawnAccount(newBankAccountModel.Username_Fk, newBankAccountModel.WithdrawnAccountNo);

            if (withdrawnAccount == null)
            {
                return("Invalid Withdrawn Account");
            }
            if (newBankAccountModel.FriendlyName.Length <= 0)
            {
                return("A New Bank Account Must Be Given A Friendly Name");
            }
            if (newBankAccountModel.AmountWithdrawn <= 10)
            {
                return("A New Bank Account Must Have Some Funds Withdrawn (10 Minimum)");
            }
            if (!IsSufficientFunds(withdrawnAccount, newBankAccountModel.AmountWithdrawn))
            {
                return("Not Enough Funds (Withdrawn Account)");
            }
            if (newBankAccountModel.Currency_Fk == withdrawnAccount.Currency_Fk)
            {
                withdrawnAccount.Balance    -= newBankAccountModel.AmountWithdrawn;
                newBankAccountModel.Balance += newBankAccountModel.AmountWithdrawn;

                accountRepo.UpdateAccount(withdrawnAccount);
            }
            if (newBankAccountModel.Currency_Fk != withdrawnAccount.Currency_Fk)
            {
                withdrawnAccount.Balance    -= newBankAccountModel.AmountWithdrawn;
                newBankAccountModel.Balance += ConvertCurrency(withdrawnAccount.Currency_Fk, newBankAccountModel.Currency_Fk,
                                                               newBankAccountModel.AmountWithdrawn);

                accountRepo.UpdateAccount(withdrawnAccount);
            }

            newBankAccountModel.DateOpened  = DateTime.Now;
            newBankAccountModel.DateExpired = newBankAccountModel.DateOpened.AddMonths(newBankAccountModel.DurationMonth);

            var newBankAccount = BankAccountModelToEntity(newBankAccountModel);

            accountRepo.AddBankAccount(newBankAccount);
            return("Success");
        }
        public void InterestsRoutine()
        {
            var accountRepo     = new AccountsRepo();
            var expiredAccounts = accountRepo.GetTodaysExpiredFixedAccounts();

            foreach (var acc in expiredAccounts)
            {
                acc.Expired = true;
                if (acc.DateExpired == null)
                {
                    continue;
                }
                var monthsBetween = (acc.DateExpired.Value.Year - acc.DateOpened.Year) * 12 + acc.DateExpired.Value.Month -
                                    acc.DateOpened.Month;
                acc.Balance = CalculateInterest(monthsBetween, acc.Balance) + acc.Balance;

                accountRepo.Update();
            }
        }
Пример #5
0
        public string TransferFunds(TransferFundsModel transferFundsModel)
        {
            var saAccountNumber = transferFundsModel.SaAccountNumber;
            var daAccountNumber = transferFundsModel.DaAccountNumber;
            var amount          = transferFundsModel.Amount;

            var accountRepo     = new AccountsRepo();
            var transactionRepo = new TransactionsRepo
            {
                Entity = accountRepo.Entity
            };

            var saBankAccount = accountRepo.GetWhitdrawnAccount(transferFundsModel.Username, saAccountNumber);
            var daBankAccount = accountRepo.GetAccountByAccountNo(daAccountNumber);

            if (saBankAccount == null)
            {
                return("Invalid Sender Account");
            }
            if (daBankAccount == null || saBankAccount == daBankAccount)
            {
                return("Make Sure That Accounts Are Valid");
            }
            if (!IsSufficientFunds(saBankAccount, amount))
            {
                return("Insufficient Funds");
            }
            if (saBankAccount.AccountType_Fk.Equals("Fixed") || daBankAccount.AccountType_Fk.Equals("Fixed"))
            {
                return("Cannot Transfer To or From a Fixed Account");
            }

            var saTransaction = new Transaction();
            var daTransaction = new Transaction();

            //TODO make Transactions cleaner
            saTransaction.Currency_Fk           = saBankAccount.Currency_Fk;
            saTransaction.AccountNo_Fk          = saBankAccount.AccountNumber;
            saTransaction.Amount                = -amount;
            saTransaction.Details               = string.Concat("Transfer To Account ", daBankAccount.AccountNumber);
            saTransaction.Transaction_Timestamp = DateTime.Now;

            saBankAccount.Balance -= amount;

            daTransaction.Currency_Fk           = daBankAccount.Currency_Fk;
            daTransaction.AccountNo_Fk          = daBankAccount.AccountNumber;
            daTransaction.Details               = string.Concat("Transfer From Account ", saBankAccount.AccountNumber);
            daTransaction.Transaction_Timestamp = DateTime.Now;

            if (IsAccountsSameCurrency(saBankAccount, daBankAccount))
            {
                daTransaction.Amount   = amount;
                daBankAccount.Balance += amount;
            }
            if (!IsAccountsSameCurrency(saBankAccount, daBankAccount))
            {
                var convertedAmount = ConvertCurrency(saBankAccount.Currency_Fk, daBankAccount.Currency_Fk, amount);

                daTransaction.Amount   = convertedAmount;
                daBankAccount.Balance += convertedAmount;
            }

            transactionRepo.AddTransaction(saTransaction);
            transactionRepo.AddTransaction(daTransaction);

            accountRepo.UpdateAccount(saBankAccount);
            accountRepo.UpdateAccount(daBankAccount);

            return("Success");
        }