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); } }
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); } }
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); } }
private void ShowAccountDetails() { using (var db = new BankingSystemV3Entities()) { var generalinformation = from c in db.Customers join b in db.Banks on c.bankID equals b.bankID join a in db.Accounts on c.accountID equals a.accountID select new { c.customerID, c.accountID, b.bankName, b.bankID, c.customerName, c.customerSurname, c.customerAddress, c.customerPhone, a.sum, a.accountType, b.bankLocation }; Console.WriteLine("\nList all users data"); foreach (var result in generalinformation) { Console.WriteLine("Customer ID :" + result.customerID + " \nAccountID " + result.accountID + " \nBankID " + result.bankID + " \nName : " + result.customerName + " \nSecond name: " + result.customerSurname + " \nAddress : " + result.customerAddress + " \nPhone : " + result.customerPhone + " \nCurrent balance : " + result.sum + " \nAccount type : " + result.accountType + " \nBank location : " + result.bankLocation + " \nBank city :" + result.bankName + " \n\n" ); } Console.WriteLine(); Console.ReadLine(); } }
public void CheckBalance() { try { using (var dbcontext = new BankingSystemV3Entities()) { Console.WriteLine("Please select the account ID : "); int id = Convert.ToInt32(Console.ReadLine()); Account a = dbcontext.Accounts .First(i => i.accountID == id); Console.WriteLine("Your current balance is " + a.sum); } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } }
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); } } }
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); } } }
private void ChangeBankName() { try { using (var dbcontext = new BankingSystemV3Entities()) { Console.WriteLine("Please select the bank ID : "); int id = Convert.ToInt32(Console.ReadLine()); Bank b = dbcontext.Banks .First(i => i.bankID == id); Console.WriteLine("Please enter the new Bank Name "); string newBankName = Console.ReadLine(); b.bankName = newBankName; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } }
public void ChangePhoneNumber() { 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 Phone Number "); int newPhoneNumber = Convert.ToInt32(Console.ReadLine()); c.customerPhone = newPhoneNumber; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); } }
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); } }