Ejemplo n.º 1
0
        private async Task <Account> SetRateForAccountAsync(Account account)
        {
            var id = account.AccountTypeId;

            _typeControl = (await _accountTypeRepository.FindAsync(id)).Type;

            switch (_typeControl)
            {
            case "Current Account":
                account.Rate = _currentAccount.Rate;
                break;

            case "Saving Account":
                account.Rate = _savingAccount.Rate;
                break;

            default:
                Console.WriteLine("Default case");
                break;
            }

            return(account);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> TransferFund(AccountTransactionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cancellationToken = new CancellationToken();
                var accountBalance    = (await _accountRepository
                                         .FindAsync(GuidEncoder.Decode(model.AccUriKey)
                                                    .ToString()))
                                        .CurrentBalance;
                var acctToCreditTypeId = model.AccountToCredit;
                if (accountBalance - model.AmountToCredit >= 0)
                {
                    var decryptedId = GuidEncoder.Decode(model.AccUriKey);
                    var account     = await _accountRepository.FindAsync(decryptedId.ToString());

                    var acctViewModel = _mapper.Map <AccountViewModel>(account);
                    account.CurrentBalance -= model.AmountToCredit;

                    //account to credit
                    var acctToCredit = await _accountRepository.FindByAccountTypeAndAppUserIdAsync(account.AppUserId, acctToCreditTypeId);

                    if (acctToCredit.IsBlocked)
                    {
                        // Todo: appropraite view needed
                        return(View());
                    }
                    acctToCredit.CurrentBalance += model.AmountToCredit;



                    //reflect txn on debited acct
                    model.AccountId                     = account.AccountId;
                    model.AppUserId                     = account.AppUserId;
                    model.DateOfTransaction             = DateTime.UtcNow;
                    model.AccountToCredit               = (await _accountTypeRepository.FindAsync(acctToCreditTypeId)).Type;
                    model.AccountToDebit                = (await _accountTypeRepository.FindAsync(account.AccountTypeId)).Type;
                    model.NewBalanceOfDebitedAccount    = account.CurrentBalance;
                    model.CurrentBalanceAccountToCredit = acctToCredit.CurrentBalance;
                    account.AccountTransactions.Add(_mapper.Map <AccountTransaction>(model));


                    //Todo: Do i need to modify accToCrediTxn to reflect more?

                    var accToCreditTxn = _mapper.Map <AccountTransactionViewModel>(model);
                    accToCreditTxn.TransactionTypeId = (await _transactionTypeRepository.FindByType("Transfer Fund Received")).TransactionTypeId;
                    accToCreditTxn.AccountId         = acctToCredit.AccountId;

                    var newTxn = _mapper.Map <AccountTransaction>(accToCreditTxn);

                    acctToCredit.AccountTransactions.Add(newTxn);


                    //Todo: Update db
                    await _unitOfWorkAccount.UpdateAsync(cancellationToken, account);

                    await _unitOfWorkAccount.UpdateAsync(cancellationToken, acctToCredit);



                    var identityUser = await _userManager.FindByIdAsync(acctToCredit.Id);

                    if (await _userManager.IsInRoleAsync(identityUser, "Bank Admin") || await _userManager.IsInRoleAsync(identityUser, "Bank Manager"))
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("UserAccountsByAccountId", new { id = GuidEncoder.Encode(acctToCredit.AccountId) }));
                    }
                }
            }


            return(View(model));
        }