Esempio n. 1
0
        private static void GUICreateBankAccount()
        {
            bool validResponse  = false;
            int  customerNumber = default;
            // int accountType = default;
            decimal creditLimit  = default;
            decimal currentSaldo = default;

            GUIShowCustomer();

            do
            {
                Console.WriteLine(@"
                        Who gets new account (customer number)?
                ");

                string guessInput = Console.ReadLine();

                // convert string to number
                validResponse = int.TryParse(guessInput, out customerNumber);
            } while (!validResponse);

            if (confirmInput())
            {
                var henkilö = context.customers.FirstOrDefault <customers>

                                  (x => x.customer_number.Equals(customerNumber));

                var newAccount = new accounts()
                {
                    account_name    = henkilö.customer_last_name,
                    account_type    = BankDefaults.BankAccount,
                    account_saldo   = currentSaldo,
                    credit_limit    = creditLimit,
                    customer_number = customerNumber
                };

                context.accounts.Add(newAccount);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        private static void GUIChangeSaldo()

        {
            GUIShowAccount();

            bool validResponse = false;

            int response = default;

            decimal response2 = default;

            do

            {
                Console.WriteLine(@"

                        Select Account?

        ");

                string guessInput = Console.ReadLine();



                // convert string to number

                validResponse = int.TryParse(guessInput, out response);
            } while (!validResponse);



            do

            {
                Console.WriteLine(@"

                        Initial change in saldo (negative for withdrawal)?

        ");

                string guessInput = Console.ReadLine();



                // convert string to number

                validResponse = decimal.TryParse(guessInput, out response2);
            } while (!validResponse);



            if (confirmInput())

            {
                accounts dummy = context.accounts.FirstOrDefault <accounts>

                                     (x => x.account_number.Equals(response));



                if (dummy.account_type.Equals(BankDefaults.BankAccount))

                {
                    dummy.account_saldo += response2;
                    context.SaveChanges();
                    Console.WriteLine($"Account {response} saldo changed...");
                }

                else

                {
                    decimal?dummy2 = dummy.account_saldo + response2;

                    if (dummy2 >= 0)
                    {
                        dummy.account_saldo += response2;
                        context.SaveChanges();
                        Console.WriteLine($"Account {response} saldo changed...");
                    }

                    else if (dummy2 >= -dummy.credit_limit)
                    {
                        dummy.account_saldo += response2;
                        context.SaveChanges();
                        Console.WriteLine($"Account uses now credit...");
                    }

                    else
                    {
                        Console.WriteLine($"Account saldo cannot go that low...");
                    }
                }
            }
        }