示例#1
0
        // Method for creating account
        private static void GUICreateCreditAccount()
        {
            int     customerNumber = default;
            decimal creditLimit    = default;
            decimal currentSaldo   = default;

            // Get customer and set saldo for new account
            GUIAskCustomerNumberAndSaldo(out customerNumber, out currentSaldo);

            // Set credit limit for new account
            GUIAskSaldo("CreditLimitSaldo", out creditLimit);

            // Create the credit account
            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    = BankDefs.CreditAccount,
                    account_saldo   = currentSaldo,
                    credit_limit    = creditLimit,
                    customer_number = customerNumber
                };

                context.accounts.Add(newAccount);
                context.SaveChanges();
            }
        }
示例#2
0
        private static void GUICreateCreditAccount()
        {
            bool validResponse = false;

            int     customerNumber = 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);

            do
            {
                Console.WriteLine(@"
                    Credit Limit?
            ");
                string guessInput = Console.ReadLine();
                // convert string to number
                validResponse = decimal.TryParse(guessInput, out creditLimit);
            } while (!validResponse);

            do
            {
                Console.WriteLine(@"
                        Current saldo?
                ");
                string guessInput = Console.ReadLine();

                // convert string to number
                validResponse = decimal.TryParse(guessInput, out currentSaldo);
            } 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    = BankDefs.CreditAccount,
                    account_saldo   = currentSaldo,
                    credit_limit    = creditLimit,
                    customer_number = customerNumber
                };
                context.accounts.Add(newAccount);
                context.SaveChanges();
            }
        }
示例#3
0
        // Method for changing saldo
        // When account is limit account and there is not enough limit,
        // changing is not allowed.
        private static void GUIChangeSaldo()
        {
            GUIShowAccount();

            int     response  = default;
            decimal response2 = default;

            GUIAskCustomerOrAccountNumber("ChangeSaldo", out response);

            GUIAskSaldo("ChangeSaldo", out response2);

            if (confirmInput())
            {
                accounts dummy = context.accounts.FirstOrDefault <accounts>
                                     (x => x.account_number.Equals(response));

                if (dummy.account_type.Equals(BankDefs.CreditAccount))
                {
                    decimal?chandedSaldo = dummy.account_saldo + response2;

                    if (chandedSaldo >= 0)
                    {
                        dummy.account_saldo += response2;

                        context.SaveChanges();

                        Console.WriteLine($"Account { response} saldo changed ...");
                    }
                    else if (chandedSaldo >= -dummy.credit_limit)
                    {
                        dummy.account_saldo += response2;

                        context.SaveChanges();

                        Console.WriteLine($"Account { response} saldo using credit now ...");
                    }
                    else
                    {
                        decimal?limitLeft = dummy.account_saldo + dummy.credit_limit;

                        Console.WriteLine($"Account { response} dont have enough limit, your limit is {limitLeft}");
                    }
                }
                else
                {
                    dummy.account_saldo += response2;

                    context.SaveChanges();

                    Console.WriteLine($"Account { response} saldo changed ...");
                }
            }
        }
示例#4
0
        private static void GUIMoveAccountToNewCustomer()
        {
            Console.WriteLine(@"
                        Move Account to new Customer
        ");

            GUIShowAccount();
            GUIShowCustomer();

            bool validResponse = false;
            int  response      = default;
            int  response2     = default;

            do
            {
                Console.WriteLine(@"
                        Select Account number to be moved
                    ");
                string guessInput = Console.ReadLine();

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

            do
            {
                Console.WriteLine(@"
                        Select new Customer to receive account
                    ");
                string guessInput = Console.ReadLine();

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

            if (confirmInput())
            {
                accounts dummy1 = context.accounts.Find(response);
                dummy1.customer_number = response2;
                context.SaveChanges();
                Console.WriteLine($"Account {response} has new customer...");
            }
        }
示例#5
0
        // Method for moving account to the other customer
        // Showing the Account List which account is going to be moved.
        // Showing the Customer List to whom the account is going to be moved.
        // After confirming account is moved to new owner and saved in database.
        private static void GUIMoveAccountToOtherCustomer()
        {
            int response  = default;
            int response2 = default;

            GUIShowAccount();
            GUIShowCustomer();

            // Get account
            GUIAskCustomerOrAccountNumber("AccountToBeTransferred", out response);
            // Get new owner
            GUIAskCustomerOrAccountNumber("AccountNewOwner", out response2);

            // Confirmed - do transferring
            if (confirmInput())
            {
                /*var accountToBeTransferred = context.accounts.FirstOrDefault<accounts>
                 *  (x => x.account_number.Equals(response));*/

                // Above can be used also, below is another way
                accounts accountToBeTransferred = context.accounts.Find(response);

                var oldOwner = context.customers.FirstOrDefault <customers>
                                   (x => x.customer_number.Equals(accountToBeTransferred.customer_number));

                var newOwner = context.customers.FirstOrDefault <customers>
                                   (x => x.customer_number.Equals(response2));

                // TODO Should it be checked that account and new owner is found?
                // If they are found, the transfer can be done.
                accountToBeTransferred.customer_number = newOwner.customer_number;
                accountToBeTransferred.account_name    = newOwner.customer_last_name;
                context.SaveChanges();

                Console.WriteLine("Account " + accountToBeTransferred.account_number + " (Saldo: "
                                  + accountToBeTransferred.account_saldo + ") has transferred. Old owner: "
                                  + oldOwner.customer_number + " (" + oldOwner.customer_first_name + " " + oldOwner.customer_last_name
                                  + "), New owner: " + newOwner.customer_number + " (" + newOwner.customer_first_name
                                  + " " + newOwner.customer_last_name + ")");
            }
        }
示例#6
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(BankDefs.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...");
                    }
                }
            }
        }