예제 #1
0
        public void DeleteCustomer(Customer customer)
        {
            var checkSumOfAccounts =
                ListOfAccounts.Where(x => x.CustomerId == customer.Id).Select(y => y.Balance).Sum();

            if (checkSumOfAccounts == 0)
            {
                ListOfAccounts.Remove(customer.Accounts.FirstOrDefault());
                ListOfCustomers.Remove(customer);
                Output.GreenColor($"Borttaget kundnummer: {customer.Id}");
            }
            else
            {
                Output.RedColor("Det går inte att ta bort en kund som har saldo större en noll på något av sina konton.");
            }
        }
예제 #2
0
        private static void AmendCreditInterestRate(Bank bank)
        {
            Output.WhiteColor("* Ändra utlåningsränta *");
            while (true)
            {
                if (AskForAccount(bank, out var id))
                {
                    var account = bank.GetSingleAccount(id);


                    // Multiply rate with 100
                    var procentBefore = account.CreditInterestRate * 100;

                    Console.WriteLine($"Nuvarande utlåningsränta (årsbasis): {procentBefore.GetProcent()}");

                    var rate = Input.AskForRate();

                    if (account.validateCreditRate(account, rate))
                    {
                        account.AmendCreditInterestRate(account, rate);
                        var procentAfter = account.CreditInterestRate * 100;

                        Output.GreenColor($"Ny utlåningsränta: {procentAfter.GetProcent()}");
                    }
                    else
                    {
                        Output.RedColor("\nUtlåningsräntan kan inte vara mindre än noll.\n");
                    }


                    //if (account.validateCreditRate())
                    //{
                    //    account.AmendCreditInterestRate(account);
                    //}
                    //else
                    //{
                    //    Output.RedColor("\nUtlåningsräntan kan inte vara mindre än noll.\n");
                    //}
                    break;
                }
                else
                {
                    Output.RedColor("Kontot existerar inte. Försök igen.");
                }
            }
        }
예제 #3
0
        private static void AmendInterestRate(Bank bank)
        {
            Output.WhiteColor("* Ändra inlåningsränta *");
            while (true)
            {
                if (AskForAccount(bank, out var id))
                {
                    var account = bank.GetSingleAccount(id);


                    // Multiply rate with 100
                    var procentBefore = account.InterestRate * 100;

                    Console.WriteLine($"Nuvarande inlåningsränta (årsbasis): {procentBefore.GetProcent()}");

                    // Get new interest rate and update it on the specific account
                    var rate = Input.AskForRate();

                    if (account.ValidateInterestRate(account, rate))
                    {
                        account.AmendInterestRate(account, rate);
                        var procentAfter = account.InterestRate * 100;

                        Output.GreenColor($"Ny inlåningsränta: {procentAfter.GetProcent()}");
                    }
                    else
                    {
                        Output.RedColor("\nInlåningsräntan kan inte vara mindre än noll.\n");
                    }



                    break;
                }
                else
                {
                    Output.RedColor("Kontot existerar inte. Försök igen.");
                }
            }
        }
예제 #4
0
        public void DeleteAccount(Account account)
        {
            // Check sum of accounts
            var checkSumOfAccounts =
                ListOfAccounts.Where(x => x.Id == account.Id).Select(y => y.Balance).Sum();

            // Count accounts
            var countAccounts = ListOfAccounts.Count(x => x.CustomerId == account.CustomerId);
            var customer      = ListOfCustomers.FirstOrDefault(x => x.Id == account.CustomerId);

            // Can not delete account if sum is not zero or there is only one account
            // (customer always need an account)
            if (checkSumOfAccounts == 0 && countAccounts > 1)
            {
                ListOfAccounts.Remove(account);
                customer.Accounts.Remove(account);
                Output.GreenColor($"Borttaget kontonummer: {account.Id}");
            }
            else
            {
                Output.RedColor("Kan ej ta bort kontot om:\n- det finns saldo\n- det är kundens enda konto");
            }
        }