Exemple #1
0
        private void UserChanges()
        {
            try
            {
                using (var dbcontext = new BankingSystemV3Entities())
                {
                    Console.WriteLine("Please select the account ID : ");
                    int      id = Convert.ToInt32(Console.ReadLine());
                    Customer c  = dbcontext.Customers
                                  .First(i => i.customerID == id);

                    Console.WriteLine("Please enter the new name  ");
                    string newFirstName = Console.ReadLine();
                    c.customerName = newFirstName;

                    Console.Write("Please enther the second name \n");
                    string newSecondName = Console.ReadLine();
                    c.customerSurname = newSecondName;

                    dbcontext.SaveChanges();
                    Console.WriteLine("Customer personal data" +
                                      " modified");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }
        }
Exemple #2
0
        private void WithdrawMoney()
        {
            try
            {
                using (var dbcontext = new BankingSystemV3Entities())
                {
                    Console.WriteLine("Please select the account ID which u want to withdraw money ");
                    int     id      = Convert.ToInt32(Console.ReadLine());
                    Account account = dbcontext.Accounts
                                      .First(i => i.accountID == id);

                    Console.WriteLine("Please enter the sum which you want to withdraw ");
                    int withdraw = Convert.ToInt32(Console.ReadLine());
                    if (withdraw <= 0 || withdraw > account.sum)
                    {
                        Console.WriteLine("Withdraw can't be completed, try again.");
                    }
                    else
                    {
                        account.sum -= withdraw;
                        Console.WriteLine("You have withdrawed " + withdraw + " from your account. Now you have " + account.sum);
                    }
                    dbcontext.SaveChanges();
                }
            }
            catch
            (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }
        }
Exemple #3
0
        private void AddMoney()
        {
            try
            {
                using (var dbcontext = new BankingSystemV3Entities())
                {
                    Console.WriteLine("Please select the account ID which u want to add money to");
                    int     id      = Convert.ToInt32(Console.ReadLine());
                    Account account = dbcontext.Accounts
                                      .First(i => i.accountID == id);
                    Console.WriteLine("Input the sum which you want to add to account");
                    int add = Convert.ToInt32(Console.ReadLine());
                    if (add <= 0)
                    {
                        Console.WriteLine("Can't deposit non positive amount");
                    }
                    else
                    {
                        account.sum += add;
                    }

                    dbcontext.SaveChanges();
                    Console.WriteLine("You have added " + add + " to your account. Now you have " + account.sum);
                }
            }
            catch
            (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }
        }
Exemple #4
0
        private void DeleteCustomer()
        {
            var dbcontext = new BankingSystemV3Entities();

            using (dbcontext)
            {
                try
                {
                    Console.WriteLine("Type the customer id which u want to delete");
                    int      input    = Convert.ToInt32(Console.ReadLine());
                    Customer customer = dbcontext.Customers.First(i => i.customerID == input);
                    dbcontext.Customers.Remove(customer);
                    dbcontext.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException);
                }
            }
        }
Exemple #5
0
        private void DeleteAccount()
        {
            var dbcontext = new BankingSystemV3Entities();

            using (dbcontext)
            {
                try
                {
                    Console.WriteLine("Type the account ID which u want to delete");
                    int     input   = Convert.ToInt32(Console.ReadLine());
                    Account account = dbcontext.Accounts.First(i => i.accountID == input);
                    dbcontext.Accounts.Remove(account);
                    dbcontext.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException);
                }
            }
        }
Exemple #6
0
        private void CreateAccount()
        {
            var dbcontext = new BankingSystemV3Entities();

            try
            {
                Console.WriteLine("Please enter the bank where you want to open account : ");
                string bname = Console.ReadLine();
                Console.WriteLine("Please enter the bank city location: ");
                string blocation = Console.ReadLine();
                Console.WriteLine("Account type: ");
                string accountType1 = Console.ReadLine();
                Console.WriteLine("Sum: ");
                int basicDeposit = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Please enter your first name:");
                string firstName = Console.ReadLine();
                Console.WriteLine("Please enter your second name: ");
                string secondName = Console.ReadLine();
                Console.WriteLine("Please enter your address: ");
                string address = Console.ReadLine();
                Console.WriteLine("Please enter your phone: ");
                int phoneNumber = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Please enter your accountNumber: ");
                int customerAccNumber = Convert.ToInt32(Console.ReadLine());



                using (dbcontext)
                {
                    var bank = new Bank
                    {
                        bankName     = bname,
                        bankLocation = blocation
                    };

                    var account = new Account
                    {
                        accountType = accountType1,
                        sum         = basicDeposit
                    };

                    var customer = new Customer
                    {
                        customerName    = firstName,
                        customerSurname = secondName,
                        customerAddress = address,
                        customerPhone   = phoneNumber,
                        customerAccNo   = customerAccNumber,
                        Bank            = bank,
                        Account         = account
                    };



                    dbcontext.Customers.Add(customer);
                    dbcontext.SaveChanges();
                    Console.WriteLine("Customer account was created. Thank you for using our services. Have a nice day.");
                    Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }
        }