예제 #1
0
        public IActionResult Transfer(TransferViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                vm.Message = "Överföring misslyckades! Se över kontouppgifterna igen";
                return(View(vm));
            }
            ;

            if (BankRepostitory.GetAccountFromAccountNumber(vm.FromAccountId) == null)
            {
                vm.Message = "Överföring misslyckades! Se över kontouppgifterna igen";
            }
            else
            {
                vm.Message = BankRepostitory.GetAccountFromAccountNumber(vm.FromAccountId).Transfer(vm.ToAccountId, (int)vm.Amount);
            }

            return(View(vm));
        }
예제 #2
0
        public string Transfer(int recieverId, int input)
        {
            if (this.Balance < input)
            {
                return("Överföring misslyckades");
            }
            this.Balance -= input;
            Customer reciever        = BankRepostitory.CustomerList.Where(c => c.CustomerAccounts.Select(a => a.AccountNumber == recieverId).FirstOrDefault()).FirstOrDefault();
            Account  recieverAccount = BankRepostitory.GetAccountFromAccountNumber(recieverId);

            if (recieverAccount == null)
            {
                return("Felaktigt mottagarkonto! Kontonummer: " + recieverId);
            }
            var customerIndex = BankRepostitory.CustomerList.IndexOf(reciever);
            var accountindex  = BankRepostitory.CustomerList[customerIndex].CustomerAccounts.IndexOf(recieverAccount);

            BankRepostitory.CustomerList[customerIndex].CustomerAccounts[accountindex].Balance += input;

            return("Överföring lyckades nya saldot är: " + this.Balance + "kr");
        }
예제 #3
0
 public BankActionController(BankRepostitory _BankRepo)
 {
     BankRepo = _BankRepo;
 }
예제 #4
0
 public HomeController(BankRepostitory _BankRepo)
 {
     BankRepo = _BankRepo;
 }