public void SpendMoneyTwiceTest() { List <BankAccount> accounts1 = new List <BankAccount>(); accounts1.Add(new BankAccount { Name = "Persoonlijke Kaart" }); User user1 = new User { Name = "Vanja van Essen", Accounts = accounts1 }; BankLogic.AddMoney(user1.Accounts[0], 250, "Initial money").Wait(); BankLogic.SpendMoney(user1.Accounts[0], 10).Wait(); BankLogic.SpendMoney(user1.Accounts[0], 10, true).Wait(); foreach (Transaction transaction in user1.Accounts[0].PreviousTransactions) { if (transaction.MayExecuteMore) { transaction.Queue().Wait(); break; } } Assert.AreEqual(220, user1.Accounts[0].Money, "Account didn't remove the money correctly"); }
// GET: History // handle if user gets here in other ways public ActionResult History() { // Create BankLogic objects and check session BankLogic bankLogic = new BankLogic(); string SessionSSN = bankLogic.CheckSessionState(); // Check if session is active, redirect to index if (!string.IsNullOrEmpty(SessionSSN)) { List<string> getAccounts = bankLogic.GetAccountsById(SessionSSN); AccountList AccountList = new AccountList(); // Get accounts to display in index view foreach (var account in getAccounts) { AccountList.account.Add(account.ToString()); } return this.RedirectToAction("Index", "Bank", new { error = SessionSSN }); } else { // Redirect to error page if session is invalid string loginStatus = "Session is invalid, please try again."; return this.RedirectToAction("Error", "Bank", new { error = loginStatus }); } }
static void Main(string[] args) { var dataAccess = new DataAccess(); var bankLogic = new BankLogic(dataAccess); int number = 10; while (number != 0) { Console.WriteLine("Awsome bank system"); Console.WriteLine("1 - Create account"); Console.WriteLine("2 - Show account info"); Console.WriteLine("3 - Deposit"); Console.WriteLine("4 - Withdrow"); Console.WriteLine("0 - Exit"); var input = Console.ReadLine(); if (!int.TryParse(input, out number)) { Console.WriteLine("Not a number"); continue; } try { ProcessDecision(number, bankLogic); } catch (InvalidAmountException e) { Console.WriteLine("Something want wrong!!! " + e.Message); } } }
public DepositeViewModel(IEventAggregator eventAggregator, Bank bank) { MyBank = bank; bankLogic = new BankLogic(bank); _eventAggregator = eventAggregator; RefreshAvailebleMoney(); }
private void Button_Click(object sender, RoutedEventArgs e) { bool con = false; if (comboBox.SelectedItem.ToString() == "Savings account") { BankLogic.AddSavingsAccount(MainPage.ChoosenCustomer, AccountNumber.Text); con = true; } else if (comboBox.SelectedItem.ToString() == "Credit account") { BankLogic.AddCreditAccount(AccountNumber.Text, MainPage.ChoosenCustomer); con = true; } else if (comboBox.SelectedItem.ToString() == "") { con = false; } if (con == true) { var _Frame = Window.Current.Content as Frame; _Frame.Navigate(typeof(MainPage)); } }
private static void Search(DatabaseRepo _repo, BankLogic bankLogic, string searchPatern) { var result = _repo.AllCustomers().Where(x => x.Name.ToLower().Contains(searchPatern) || x.City.ToLower().Contains(searchPatern)).ToList(); if (!result.Any()) { Console.WriteLine("Nein nobody here"); } else { foreach (var item in result) { Console.WriteLine($"{item.CustomerId} : {item.Name}"); } } DrawStarLine(); Console.WriteLine(); Console.WriteLine("Search again press 0 else press 1"); var input = Console.ReadLine(); if (input == "0") { Console.WriteLine(); DrawStarLine(); Console.WriteLine(); Console.WriteLine("Search"); var result1 = Console.ReadLine(); Search(_repo, bankLogic, result1); } else { ClearAndReoload(_repo, bankLogic); } }
public void GetCustomerAccount() { var bankLogic = new BankLogic(); var accounts = new List <Account>(); var acc1 = new Account { Balance = 1111, AccountId = 1, CustomerId = 1 }; var acc2 = new Account { Balance = 3333, AccountId = 2, CustomerId = 1 }; var acc3 = new Account { Balance = 444, AccountId = 3, CustomerId = 3 }; accounts.Add(acc1); accounts.Add(acc2); accounts.Add(acc3); var result = bankLogic.GetCustomersAccounts(1, accounts).Count; Assert.Equal(2, result); }
static void Main(string[] args) { var _repo = new DatabaseRepo(); var banklogic = new BankLogic(); _repo.ImportAllData(); DisplayMenu(_repo, banklogic); }
private void Button_Click(object sender, RoutedEventArgs e) { MainPage.ChoosenCustomer = BankLogic.AddCustomer(NameText.Text, SsnText.Text); textBlock.Visibility = Visibility.Visible; var _Frame = Window.Current.Content as Frame; _Frame.Navigate(typeof(MainPage)); }
public static BankLogic GetBankLogic() { if (_logic == null) { _logic = new BankLogic(); } return(_logic); }
public GetCashViewModel(IEventAggregator eventAggregator, Bank myBank) { MyBank = myBank; bankLogic = new BankLogic(MyBank); MyBank.Balance = bankLogic.GetBalance(); _eventAggregator = eventAggregator; _eventAggregator.Subscribe(this); ReturnedMoney = new BindableCollection <KeyValuePair <int, int> >(); }
private static void ClearAndReoload(DatabaseRepo _repo, BankLogic bankLogic) { DrawStarLine(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); Console.Clear(); Console.Beep(); DisplayMenu(_repo, bankLogic); }
private void Button_Click(object sender, RoutedEventArgs e) { if (BankLogic.Withdraw(MainPage.ChoosenAccount, double.Parse(Textsum.Text)) == true) { Transaction transnew = new Transaction(MainPage.ChoosenAccount.AccountNumber, DateTime.Now, double.Parse(Textsum.Text), MainPage.ChoosenAccount.Balance); MainPage.ChoosenAccount.TransactionList.Add(transnew); } this.Frame.Navigate(typeof(MainMeny)); }
public void TestAddBankAccount() { User user = new User() { Id = Guid.NewGuid().ToString(), dateofcreation = DateTime.Now, dummyaccount = true, Name = "Test" }; NUnit.Framework.Assert.DoesNotThrow(() => BankLogic.AddBankAccount(user, "test", 1000000, true)); }
private static void ProcessDecision(int number, BankLogic bankLogic) { switch (number) { case 1: Console.WriteLine("Enter owner"); var owner = Console.ReadLine(); bankLogic.CreateAccount(owner); break; case 2: var data = bankLogic.GetAccountData(); Console.WriteLine(data); break; case 3: Console.WriteLine("Enter amount to deposit"); var depositText = Console.ReadLine(); decimal deposit = 0; if (Decimal.TryParse(depositText, out deposit)) { bankLogic.DepositAmount(deposit); } else { Console.WriteLine("Not a number"); } break; case 4: Console.WriteLine("Enter amount to withdrow"); var withdrowText = Console.ReadLine(); decimal withdrow = 0; if (decimal.TryParse(withdrowText, out withdrow)) { Console.WriteLine(bankLogic.WithrowAmount(withdrow) ? "Success!" : "Failure!"); } else { Console.WriteLine("Not a number"); } break; case 0: Console.WriteLine("Thanks"); break; default: Console.WriteLine("Wrong number"); break; } }
public void DepositAmountAmountShouldBeGreaterThan0() { //Given (arrange) var dataAccessMock = new Mock <IDataAccess>(); dataAccessMock.Setup(p => p.LoadBankAccount(It.IsAny <int>())).Returns <int>(p => new BankAccount()); var sut = new BankLogic(dataAccessMock.Object); //When (act) sut.DepositAmount(0); //Then (assert) }
public MainWindow() { InitializeComponent(); gridLogin.Visibility = Visibility.Visible; ClearAll(); gridClientPanel.Visibility = Visibility.Hidden; HttpClientChannel channel = new HttpClientChannel(); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownClientType(typeof(BankLogic), "http://localhost:12345/Bank"); bank = new BankLogic(); }
private void Button_Click(object sender, RoutedEventArgs e) { BankLogic.DepositMoney(MainPage.ChoosenAccount, double.Parse(sum.Text)); Transaction transnew = new Transaction(MainPage.ChoosenAccount.AccountNumber, DateTime.Now, double.Parse(sum.Text), MainPage.ChoosenAccount.Balance); sumValue.Text = sum.Text; sumValue.Visibility = Visibility.Visible; sumText.Visibility = Visibility.Visible; MainPage.ChoosenAccount.TransactionList.Add(transnew); this.Frame.Navigate(typeof(MainMeny)); //Thread.Sleep(2000); }
public void ShowAccountDataShoulReturnEmptyStringWhenAccountDNE() { //Given (arrange) var dataAccessMock = new Mock <IDataAccess>(); dataAccessMock.Setup(p => p.LoadBankAccount(It.IsAny <int>())).Throws(new FileNotFoundException()); var sut = new BankLogic(dataAccessMock.Object); //When (act) var result = sut.GetAccountData(); //Then (assert) Assert.AreEqual(string.Empty, result); }
// GET: Done // Clear session and display a good bye message public ActionResult Done() { // Get bank logic object and current session BankLogic bankLogic = new BankLogic(); string ssn = (string)Session["SSN"]; // Send log out successfull to log bankLogic.LoggingOfEvents("Logout_success", ssn, " ", 0); // Clear session Session.Abandon(); return View(); }
public ActionResult History(string accountNumber) { // Check if account number is valid if (!string.IsNullOrEmpty(accountNumber)) { // Create BankLogic object and get 5 latest events BankLogic bankLogic = new BankLogic(); List<string> accountHistory = bankLogic.GetAccountInformation(accountNumber, 5); // If error is returned go to error page and display error if (accountHistory[0] == "false") { return this.RedirectToAction("Error", "Bank", new { error = accountHistory[1] }); } else { AccountInformation accountInfo = new AccountInformation(); List<string> receipt = (List<string>)Session["numberOfBills"]; // Check if unit has receipt paper if (int.Parse(receipt[4]) < 2) { //Disable receipt button accountInfo.receipt = "disabled"; } // List all account events for (int i = 2; i < accountHistory.Count; i++) { accountInfo.entry.Add(accountHistory[i]); } // Add account info to be displayed in view accountInfo.accountRaw = accountNumber; accountInfo.account = accountHistory[0]; //Get session info and add to event log string ssn = (string)Session["SSN"]; bankLogic.LoggingOfEvents("View_amount", ssn, accountNumber, 0); return View(accountInfo); } } else { return this.RedirectToAction("Index", "Bank"); } }
public void AddMoneyTest() { List <BankAccount> accounts = new List <BankAccount>(); accounts.Add(new BankAccount { Name = "Persoonlijke Kaart" }); User user1 = new User { Name = "Vanja van Essen", Accounts = accounts }; BankLogic.AddMoney(user1.Accounts[0], 10, "Initial money").Wait(); Assert.AreEqual(10, user1.Accounts[0].Money, "Account didn't get the money correctly"); }
public void WithrowAmountWhenAmountEqalsToBalansShouldWithrow() { //Given (arrange) var dataAccessMock = new Mock <IDataAccess>(); dataAccessMock.Setup(p => p.LoadBankAccount(It.IsAny <int>())).Returns <int>(p => new BankAccount() { Number = p, Value = 10 }); var sut = new BankLogic(dataAccessMock.Object); //When (act) var result = sut.WithrowAmount(10); //Then (assert) Assert.IsTrue(result); }
private async void ProcessVerificationResponse(IPNContext ipnContext) { IDataService _dataService = DeBank.Library.DAL.MockingData.GetMockDataService(); if (ipnContext.Verification.Equals("VERIFIED")) { var item = TempData.Peek("carryoverkey") as Transaction; BankLogic logic = new BankLogic(); await logic.SpendMoney(StaticResources.CurrentUser.CurrentBankAccount, item.Amount); } else if (ipnContext.Verification.Equals("INVALID")) { //Log for manual investigation } else { //Log error } }
public async Task <IActionResult> TransferMoney(Transaction transaction) { try { BankLogic bank = WebBankLogic.GetBankLogic(); if (_dataService.ReturnAllBankAccounts().Where(a => a.Id == transaction.InteractedAccount.Id).Any()) { transaction.Id = Guid.NewGuid().ToString(); transaction.Account = StaticResources.CurrentUser.CurrentBankAccount; transaction.InteractedAccount = _dataService.ReturnAllBankAccounts().Where(a => a.Id == transaction.InteractedAccount.Id).FirstOrDefault(); await bank.TransferMoney(transaction.Account, transaction.InteractedAccount, transaction.Amount); return(RedirectToAction("SuccesfullTrade", "RegularUserMoneyMutation")); } else { ViewBag.Message = "User was not found"; return(View()); } } #pragma warning disable CS0168 // Variable is declared but never used catch (NullReferenceException ex) #pragma warning restore CS0168 // Variable is declared but never used { ViewBag.Message = "Wrong value input, please try a valid value"; return(View()); } #pragma warning disable CS0168 // Variable is declared but never used catch (ArgumentNullException ex) #pragma warning restore CS0168 // Variable is declared but never used { ViewBag.Message = "Wrong value input, please try a valid value"; return(View()); } #pragma warning disable CS0168 // Variable is declared but never used catch (Exception ex) #pragma warning restore CS0168 // Variable is declared but never used { ViewBag.Message = "Something went wrong, try again"; return(View()); } }
/// <summary> /// Exports the specified instance properties to the provided stream. /// </summary> /// <param name="qif">The <seealso cref="T:QifDom"/> to export.</param> /// <param name="stream">Stream.</param> /// <param name="encoding">Encoding.</param> /// <remarks>This will overwrite an existing file.</remarks> public static void ExportStream(QifDom qif, Stream stream, Encoding encoding = null) { encoding = encoding ?? Encoding.UTF8; using (StreamWriter writer = new StreamWriter(stream, encoding, 512, true)) { writer.AutoFlush = true; AccountListLogic.Export(writer, qif.AccountListTransactions); AssetLogic.Export(writer, qif.AssetTransactions); BankLogic.Export(writer, qif.BankTransactions); CashLogic.Export(writer, qif.CashTransactions); CategoryListLogic.Export(writer, qif.CategoryListTransactions); ClassListLogic.Export(writer, qif.ClassListTransactions); CreditCardLogic.Export(writer, qif.CreditCardTransactions); InvestmentLogic.Export(writer, qif.InvestmentTransactions); LiabilityLogic.Export(writer, qif.LiabilityTransactions); MemorizedTransactionListLogic.Export(writer, qif.MemorizedTransactionListTransactions); } }
public void TestReturnTransactionsWithinTimeFrame() { BankAccount account = new BankAccount() { Id = Guid.NewGuid().ToString(), dateofcreation = DateTime.Now, dummyaccount = true, PreviousTransactions = new List <Transaction>() { new Transaction() { Id = Guid.NewGuid().ToString(), Amount = 100, LastExecuted = DateTime.Now, dummytransaction = true, } } }; NUnit.Framework.Assert.DoesNotThrow(async() => await BankLogic.ReturnTransactionsWithinTimeFrame(account, 100, Library.Enums.PositiveNegativeOrAllTransactions.none)); }
private static async void TransferMoney(object obj) { if (!(obj is TransferMoneyStruct)) { return; } TransferMoneyStruct strct = (TransferMoneyStruct)obj; await BankLogic.TransferMoney(strct.Account1, strct.Account2, 10, "Testen"); Console.WriteLine("Users (AFTER):"); foreach (User user in strct.Users) { Console.WriteLine(" " + user.Name + ":"); foreach (BankAccount account in user.Accounts) { Console.WriteLine(" - " + account.Name + ":"); Console.WriteLine(" Money: " + account.Money); } } }
/// <summary> /// Exports the specified instance properties to the specified file. /// </summary> /// <param name="qif">The <seealso cref="T:QifDom"/> to export.</param> /// <param name="fileName">Name of the file.</param> /// <param name="encoding"> /// The encoding to use when exporting the QIF file. This defaults to UTF8 /// when not specified. /// </param> /// <remarks>This will overwrite an existing file.</remarks> public static void ExportFile(QifDom qif, string fileName, Encoding encoding = null) { if (File.Exists(fileName)) { File.SetAttributes(fileName, FileAttributes.Normal); } using (StreamWriter writer = new StreamWriter(fileName, false, encoding ?? Encoding.UTF8)) { writer.AutoFlush = true; AccountListLogic.Export(writer, qif.AccountListTransactions, qif.Configuration); AssetLogic.Export(writer, qif.AssetTransactions, qif.Configuration); BankLogic.Export(writer, qif.BankTransactions, qif.Configuration); CashLogic.Export(writer, qif.CashTransactions, qif.Configuration); CategoryListLogic.Export(writer, qif.CategoryListTransactions, qif.Configuration); ClassListLogic.Export(writer, qif.ClassListTransactions, qif.Configuration); CreditCardLogic.Export(writer, qif.CreditCardTransactions, qif.Configuration); InvestmentLogic.Export(writer, qif.InvestmentTransactions, qif.Configuration); LiabilityLogic.Export(writer, qif.LiabilityTransactions, qif.Configuration); MemorizedTransactionListLogic.Export(writer, qif.MemorizedTransactionListTransactions, qif.Configuration); } }
// GET: Index // Display login page public ActionResult Index() { BankLogic ATMStatus = new BankLogic(); // Change ATM units string ATMID = "A1"; // Ok //string ATMID = "B2"; // Out of Service //string ATMID = "A2"; // Low amount of currency //string ATMID = "C1"; // No currency // Set current ATM in session and check status Session["ATMID"] = ATMID; List<string> checkStatus = ATMStatus.CheckATMStatus(ATMID); // Show log in page or error page depending on status if (checkStatus[0] == "Ok") { return View(); } else { return this.RedirectToAction("Error", "Bank", new { error = checkStatus[1] }); } }
// GET: Bank // handle if user gets here in other ways public ActionResult Index(string error) { // Create BankLogic and Account List obects BankLogic bankLogic = new BankLogic(); string loginStatus = null; string sessionState = bankLogic.CheckSessionState(); AccountList AccountList = new AccountList(); // Check if user was redirected if (!string.IsNullOrEmpty(error)) { List<string> getAccounts = bankLogic.GetAccountsById(error); // Check if user has bankaccounts, else redirect to error page if (getAccounts[0] == "false") { return this.RedirectToAction("Error", "Bank", new { error = getAccounts[1] }); } else { // Get list of accounts foreach (var account in getAccounts) { AccountList.account.Add(account.ToString()); } } return View(AccountList); } // Check if session is active else if (!string.IsNullOrEmpty(sessionState)) { List<string> getAccounts = bankLogic.GetAccountsById(sessionState); // Check if user has bankaccounts, else redirect to error page if (getAccounts[0] == "false") { return this.RedirectToAction("Error", "Bank", new { error = getAccounts[1] }); } else { // Get list of accounts foreach (var account in getAccounts) { AccountList.account.Add(account.ToString()); } } return View(AccountList); } // Handle unexpected errors else { if (string.IsNullOrEmpty(loginStatus)) { loginStatus = "Unhandled error"; } return this.RedirectToAction("Error", "Bank", new { error = loginStatus }); } }
public ActionResult Index(string SSN, string pin) { // Create BankLogic and Account List obects BankLogic bankLogic = new BankLogic(); AccountList AccountList = new AccountList(); List<string> loginStatus = new List<string>(); // Check log in credentials if (!string.IsNullOrEmpty(SSN) && !string.IsNullOrEmpty(pin)) { loginStatus = bankLogic.LogIn(SSN, pin); // Check log in status if (loginStatus[0] == "Ok") { // Get list of accounts List<string> getAccounts = bankLogic.GetAccountsById(SSN); foreach (var account in getAccounts) { AccountList.account.Add(account.ToString()); } return View(AccountList); } else { return this.RedirectToAction("Error", "Bank", new { error = loginStatus[1] }); } } else { return this.RedirectToAction("Error", "Bank", new { error = loginStatus }); } }
// GET: Landing // Confirmation page when taking out money public ActionResult Landing(string quantity, string account) { // Create BankLogic object and prepare variables BankLogic bankLogic = new BankLogic(); int sum = int.Parse(quantity); // Get number of bills that was taken out and if transaction was successfull List<string> receipt = (List<string>)Session["numberOfBills"]; List<string> message = bankLogic.WithdrawFromAccount(sum, account); if (message[0] == "Ok") { WithdrawalConfirmation confirm = new WithdrawalConfirmation(); // Check if unit has receipt paper if (int.Parse(receipt[4]) < 1) { confirm.receipt = "disabled"; } // Prepare variables to be passsed to view confirm.sum = quantity; confirm.account = account; confirm.value100 = message[1]; confirm.value200 = message[2]; confirm.value500 = message[3]; confirm.value1000 = message[4]; return View(confirm); } else { return this.RedirectToAction("Error", "Bank", new { error = message[1] }); } }
public ActionResult Receipt(string acc, string quantity, string accRaw) { // Create BankLogic Object BankLogic bankLogic = new BankLogic(); // Check if the receipt is for withdrawal if (string.IsNullOrEmpty(accRaw)) { // Remove one length bankLogic.subtractFromReceipt(1, (string)Session["ATMID"]); // Prepare receipt info to be passed in to view Receipt receipt = new Receipt(); receipt.acc = acc; receipt.sum = quantity; receipt.receiptType = 1; // Log receipt event string ssn = (string)Session["SSN"]; bankLogic.LoggingOfEvents("Print_Success", ssn, " ", 0); return View(receipt); } //Check if the receipt is for history and balance else if (!string.IsNullOrEmpty(accRaw)) { // Prepare variables and objects Receipt receipt = new Receipt(); List<string> accountHistory = bankLogic.GetAccountInformation(accRaw, 25); // Remove two lengths bankLogic.subtractFromReceipt(2, (string)Session["ATMID"]); // Prepare receipt info to be passed in to view for (int i = 2; i < accountHistory.Count; i++) { receipt.entry.Add(accountHistory[i]); } receipt.acc = acc; receipt.receiptType = 2; // Log receipt event string ssn = (string)Session["SSN"]; bankLogic.LoggingOfEvents("Print_Success", ssn, " ", 0); return View(receipt); } else { return this.RedirectToAction("Index", "Home"); } }
// GET: Withdrawal // handle if user gets here in other ways public ActionResult Withdrawal() { // Create BankLogic objects and check session BankLogic bankLogic = new BankLogic(); string sessionState = bankLogic.CheckSessionState(); // Check if session is active then redirect to index if (!string.IsNullOrEmpty(sessionState)) { List<string> getAccounts = bankLogic.GetAccountsById(sessionState); AccountList AccountList = new AccountList(); foreach (var account in getAccounts) { AccountList.account.Add(account.ToString()); } return this.RedirectToAction("Index", "Bank", new { error = sessionState }); } else { // Redirect to error page if session is invalid string loginStatus = "Session is invalid, please try again."; return this.RedirectToAction("Error", "Bank", new { error = loginStatus }); } }
public static void DisplayMenu(DatabaseRepo _repo, BankLogic bankLogic) { DrawStarLine(); Console.WriteLine("* Welcome to ElPaplito, the worst bank in the world! *"); DrawStarLine(); Console.WriteLine("Importing from " + _repo.GetCurrentTextFile()); Console.WriteLine("Total Customers: " + _repo.AllCustomers().Count); Console.WriteLine("Total Accounts: " + _repo.AllAccounts().Count); Console.WriteLine("Total balance: " + _repo.AllAccounts().Sum(x => x.Balance)); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); Console.WriteLine("0. Search"); Console.WriteLine("1. Show customer"); Console.WriteLine("2. Withdraw"); Console.WriteLine("3. Deposit"); Console.WriteLine("4. Transaction"); Console.WriteLine("5. Exit and save"); Console.WriteLine("6. Create customer"); Console.WriteLine("7. Delete customer"); Console.WriteLine("8. Create account"); Console.WriteLine("9. Delete account"); Console.Write("Enter your choice: "); var userChoice = Console.ReadLine(); if (userChoice == "0") { Console.WriteLine(); Console.WriteLine("Search:"); var result = Console.ReadLine(); Search(_repo, bankLogic, result.ToLower()); } else if (userChoice == "1") { Console.WriteLine(); Console.WriteLine("CustomerId:"); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } var result = ShowCustomer(_repo, customerId); Console.WriteLine("CustomerId: " + result.CustomerId); Console.WriteLine("Orginisation: " + result.OrginisationNumber); Console.WriteLine("Name: " + result.Name); Console.WriteLine("Adress: " + result.Adress + " Zipcode: " + result.ZipCode + " City: " + result.City + " Country: " + result.Country); Console.WriteLine(); var accs = bankLogic.GetCustomersAccounts(customerId, _repo.AllAccounts()); if (accs.Count == 0) { Console.Write("This customer does not have any accounts."); } else { decimal total = 0; foreach (var acc in accs) { total += acc.Balance; Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Total balance: " + total); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "2") { Console.WriteLine(); Console.WriteLine("CustomerId: "); var fromCusId = Int32.Parse(Console.ReadLine()); while (_repo.AllCustomers().FirstOrDefault(x => x.CustomerId == fromCusId) == null) { Console.WriteLine("Could not find any customer, try again..."); fromCusId = Int32.Parse(Console.ReadLine()); } var cusAccs = bankLogic.GetCustomersAccounts(fromCusId, _repo.AllAccounts()); foreach (var acc in cusAccs) { Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Which account?"); var fromAccId = Int32.Parse(Console.ReadLine()); var fromAcc = _repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId); while (_repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId) == null) { Console.WriteLine("Could not find account, try again..."); fromAccId = Int32.Parse(Console.ReadLine()); } Console.WriteLine("Amount:"); var amount = (Console.ReadLine()); if (amount.Contains("-") || decimal.Parse(amount) > fromAcc.Balance) { Console.WriteLine("Withdraw failed!"); } else { bankLogic.Withdraw(decimal.Parse(amount), fromAccId, _repo); } Console.WriteLine("You now have " + fromAcc.Balance + "$ left!"); Console.ReadKey(); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "3") { Console.WriteLine(); Console.WriteLine("CustomerId: "); var fromCusId = Int32.Parse(Console.ReadLine()); while (_repo.AllCustomers().FirstOrDefault(x => x.CustomerId == fromCusId) == null) { Console.WriteLine("Could not find any customer, try again..."); int.TryParse(Console.ReadLine(), out fromCusId); Console.WriteLine("CustomerId: "); fromCusId = Int32.Parse(Console.ReadLine()); } var cusAccs = bankLogic.GetCustomersAccounts(fromCusId, _repo.AllAccounts()); foreach (var acc in cusAccs) { Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Which account?"); var fromAccId = Int32.Parse(Console.ReadLine()); var fromAcc = _repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId); while (_repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId) == null) { Console.WriteLine("Could not find account, try again..."); int.TryParse(Console.ReadLine(), out fromAccId); Console.WriteLine("AccountId: "); fromAccId = Int32.Parse(Console.ReadLine()); } Console.WriteLine("Amount:"); var amount = (Console.ReadLine()); if (amount.Contains("-")) { Console.WriteLine("No negative number are allowed"); } else { bankLogic.Deposit(decimal.Parse(amount), fromAccId, _repo); } Console.WriteLine("You now have " + fromAcc.Balance + "$ on your account!"); Console.ReadKey(); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "4") { int fromAcc = 0; int toAcc = 0; Console.WriteLine(); Console.WriteLine("Transaction"); Console.WriteLine(); Console.WriteLine("From Account: Enter Account id"); Console.WriteLine(); while (!int.TryParse(Console.ReadLine(), out fromAcc)) { Console.WriteLine("Please Enter a valid account id!"); } Console.WriteLine(); Console.WriteLine("To Account: Enter Account id"); Console.WriteLine(); while (!int.TryParse(Console.ReadLine(), out toAcc)) { Console.WriteLine("Please Enter a valid account id!"); } Console.WriteLine(); Console.WriteLine("Enter amount: "); Console.WriteLine(); decimal amount = decimal.Parse(Console.ReadLine()); var result = bankLogic.Transaction(_repo, fromAcc, toAcc, amount); if (result == "Success") { Console.WriteLine($"Successful transaction. Transfered: {amount}$ from account: {fromAcc} to account: {toAcc}"); } else { Console.WriteLine("Failed transaction"); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "5") { Console.WriteLine(); Console.WriteLine("Exit and save"); _repo.SaveDateToTextFile(); Console.WriteLine("Info has been saved to: " + _repo.GetCurrentTextFile()); Console.WriteLine(); Console.WriteLine("Total Customers: " + _repo.AllCustomers().Count); Console.WriteLine("Total Accounts: " + _repo.AllAccounts().Count); Console.WriteLine("Total balance:" + _repo.AllAccounts().Sum(x => x.Balance)); Thread.Sleep(5000); Environment.Exit(0); } else if (userChoice == "6") { int orgNo = 0; Console.WriteLine(); Console.WriteLine("Create customer:"); Console.WriteLine(); Console.WriteLine("Name:"); var name = Console.ReadLine(); while (String.IsNullOrEmpty(name)) { Console.WriteLine("Please enter a valid Name"); name = Console.ReadLine(); } Console.WriteLine("Organisation number:"); while (!int.TryParse(Console.ReadLine(), out orgNo)) { Console.WriteLine("Please Enter a valid numerical value!"); Console.WriteLine("Please Enter an ID number:"); } Console.WriteLine("Adress:"); var adress = Console.ReadLine(); while (String.IsNullOrEmpty(adress)) { Console.WriteLine("Please enter a valid Adress"); adress = Console.ReadLine(); } Console.WriteLine("City:"); var city = Console.ReadLine(); while (String.IsNullOrEmpty(city)) { Console.WriteLine("Please enter a valid city"); city = Console.ReadLine(); } Console.WriteLine("State:"); var state = Console.ReadLine(); Console.WriteLine("ZipCode:"); var zipcode = Console.ReadLine(); while (String.IsNullOrEmpty(zipcode)) { Console.WriteLine("Please enter a valid zipcode"); zipcode = Console.ReadLine(); } Console.WriteLine("Country:"); var country = Console.ReadLine(); while (String.IsNullOrEmpty(country)) { Console.WriteLine("Please enter a valid country"); country = Console.ReadLine(); } Console.WriteLine("Phone:"); var phone = Console.ReadLine(); while (String.IsNullOrEmpty(phone)) { Console.WriteLine("Please enter a valid phone"); phone = Console.ReadLine(); } var result = _repo.CreateCustomer(name, adress, phone, city, country, zipcode, orgNo.ToString(), state); if (result) { DrawStarLine(); Console.WriteLine("Customer added dount forget to save!"); ClearAndReoload(_repo, bankLogic); } else { Console.WriteLine("Shit happens try again"); Console.WriteLine(); ClearAndReoload(_repo, bankLogic); } } else if (userChoice == "7") { Console.WriteLine(); Console.WriteLine("Delete customer"); Console.WriteLine(); Console.WriteLine("Enter CustomerId: "); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } if (bankLogic.ValidateDeleteCustomer(customerId, _repo.AllAccounts()) == false) { Console.WriteLine("Can´t delete customer, customer still have money left!"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { _repo.DeleteCustomer(customerId); Console.WriteLine("Customer deleted, dount forget to save"); Console.WriteLine(); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "8") { Console.WriteLine(); Console.WriteLine("Create account"); Console.WriteLine(); Console.WriteLine("Enter CustomerId: "); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } _repo.CreateAccount(customerId); Console.WriteLine("Your account has been created"); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "9") { Console.WriteLine(); Console.WriteLine("Delete account"); Console.WriteLine(); Console.WriteLine("Enter Account id: "); int accountId; int.TryParse(Console.ReadLine(), out accountId); while (ValidateAccountId(accountId, _repo) == false) { Console.WriteLine("ERROR! Invalid accountId or account still have money"); DisplayMenu(_repo, bankLogic); int.TryParse(Console.ReadLine(), out accountId); } _repo.DeleteAccount(accountId); Console.WriteLine("Account deleted"); ClearAndReoload(_repo, bankLogic); } Console.ReadLine(); }
/// <summary> /// Imports a QIF file stream reader and returns a QifDom object. /// </summary> /// <param name="reader">The stream reader pointing to an underlying QIF file to import.</param> /// <param name="config">The configuration to use while importing raw data</param> /// <returns>A QifDom object of transactions imported.</returns> public static QifDom ImportFile(StreamReader reader, Configuration config = null) { QifDom result = new QifDom(config); // Read the entire file string input = reader.ReadToEnd(); // Split the file by header types string[] transactionTypes = Regex.Split(input, @"^(!.*)$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); // Loop through the transaction types for (int i = 0; i < transactionTypes.Length; i++) { // Get the exact transaction type string transactionType = transactionTypes[i].Replace("\r", "").Replace("\n", "").Trim(); // If the string has a value if (transactionType.Length > 0) { // Check the transaction type switch (transactionType) { case Headers.Bank: // Increment the array counter i++; // Extract the transaction items string bankItems = transactionTypes[i]; // Import all transaction types result.BankTransactions.AddRange(BankLogic.Import(bankItems, result.Configuration)); // All done break; case Headers.AccountList: // Increment the array counter i++; // Extract the transaction items string accountListItems = transactionTypes[i]; // Import all transaction types result.AccountListTransactions.AddRange(AccountListLogic.Import(accountListItems, result.Configuration)); // All done break; case Headers.Asset: // Increment the array counter i++; // Extract the transaction items string assetItems = transactionTypes[i]; // Import all transaction types result.AssetTransactions.AddRange(AssetLogic.Import(assetItems, result.Configuration)); // All done break; case Headers.Cash: // Increment the array counter i++; // Extract the transaction items string cashItems = transactionTypes[i]; // Import all transaction types result.CashTransactions.AddRange(CashLogic.Import(cashItems, result.Configuration)); // All done break; case Headers.CategoryList: // Increment the array counter i++; // Extract the transaction items string catItems = transactionTypes[i]; // Import all transaction types result.CategoryListTransactions.AddRange(CategoryListLogic.Import(catItems, result.Configuration)); // All done break; case Headers.ClassList: // Increment the array counter i++; // Extract the transaction items string classItems = transactionTypes[i]; // Import all transaction types result.ClassListTransactions.AddRange(ClassListLogic.Import(classItems, result.Configuration)); // All done break; case Headers.CreditCard: // Increment the array counter i++; // Extract the transaction items string ccItems = transactionTypes[i]; // Import all transaction types result.CreditCardTransactions.AddRange(CreditCardLogic.Import(ccItems, result.Configuration)); // All done break; case Headers.Investment: // Increment the array counter i++; // Extract the transaction items string investItems = transactionTypes[i]; // Import all transaction types result.InvestmentTransactions.AddRange(InvestmentLogic.Import(investItems, result.Configuration)); // All done break; case Headers.Liability: // Increment the array counter i++; // Extract the transaction items string liabilityItems = transactionTypes[i]; // Import all transaction types result.LiabilityTransactions.AddRange(LiabilityLogic.Import(liabilityItems, result.Configuration)); // All done break; case Headers.MemorizedTransactionList: // Increment the array counter i++; // Extract the transaction items string memItems = transactionTypes[i]; // Import all transaction types result.MemorizedTransactionListTransactions.AddRange(MemorizedTransactionListLogic.Import(memItems, result.Configuration)); // All done break; default: // Don't do any processing break; } } } return(result); }
private void Start() { logic = GetComponent <BankLogic> (); signinButton.onClick.AddListener(delegate(){ feedback.text = logic.signIn(inputFields[0].text, inputFields[1].text); }); }
/// <summary> /// Imports a QIF file stream reader and returns a QifDom object. /// </summary> /// <param name="reader">The stream reader pointing to an underlying QIF file to import.</param> /// <param name="config">The configuration to use while importing raw data</param> /// <returns>A QifDom object of transactions imported.</returns> public static QifDom ImportFile(TextReader reader, Configuration config = null) { QifDom result = new QifDom(config); // Read the entire file string input = reader.ReadToEnd(); // Split the file by header types string[] transactionTypes = Regex.Split(input, @"^(!.*)$", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace); // Remember the last account name we saw so we can link its transactions to it. string currentAccountName = string.Empty; // Loop through the transaction types for (int i = 0; i < transactionTypes.Length; i++) { // Get the exact transaction type string transactionType = transactionTypes[i].Replace("\r", "").Replace("\n", "").Trim(); // If the string has a value if (transactionType.Length > 0) { // Check the transaction type switch (transactionType) { case Headers.Bank: // Increment the array counter i++; // Extract the transaction items string bankItems = transactionTypes[i]; // Import all transaction types var transactions = BankLogic.Import(bankItems, result.Configuration); // Associate the transactions with last account we saw. foreach (var transaction in transactions) { transaction.AccountName = currentAccountName; } result.BankTransactions.AddRange(transactions); // All done break; case Headers.AccountList: // Increment the array counter i++; // Extract the transaction items string accountListItems = transactionTypes[i]; // Import all transaction types var accounts = AccountListLogic.Import(accountListItems, result.Configuration); // Remember account so transaction following can be linked to it. currentAccountName = accounts.Last().Name; result.AccountListTransactions.AddRange(accounts); // All done break; case Headers.Asset: // Increment the array counter i++; // Extract the transaction items string assetItems = transactionTypes[i]; // Import all transaction types result.AssetTransactions.AddRange(AssetLogic.Import(assetItems, result.Configuration)); // All done break; case Headers.Cash: // Increment the array counter i++; // Extract the transaction items string cashItems = transactionTypes[i]; // Import all transaction types result.CashTransactions.AddRange(CashLogic.Import(cashItems, result.Configuration)); // All done break; case Headers.CategoryList: // Increment the array counter i++; // Extract the transaction items string catItems = transactionTypes[i]; // Import all transaction types result.CategoryListTransactions.AddRange(CategoryListLogic.Import(catItems, result.Configuration)); // All done break; case Headers.ClassList: // Increment the array counter i++; // Extract the transaction items string classItems = transactionTypes[i]; // Import all transaction types result.ClassListTransactions.AddRange(ClassListLogic.Import(classItems, result.Configuration)); // All done break; case Headers.TagList: // Increment the array counter i++; // Extract the transaction items string tagListItems = transactionTypes[i]; // Import all transaction types result.TagListTransactions.AddRange(TagListLogic.Import(tagListItems, result.Configuration)); // All done break; case Headers.CreditCard: // Increment the array counter i++; // Extract the transaction items string ccItems = transactionTypes[i]; // Import all transaction types result.CreditCardTransactions.AddRange(CreditCardLogic.Import(ccItems, result.Configuration)); // All done break; case Headers.Investment: // Increment the array counter i++; // Extract the transaction items string investItems = transactionTypes[i]; // Import all transaction types result.InvestmentTransactions.AddRange(InvestmentLogic.Import(investItems, result.Configuration)); // All done break; case Headers.Liability: // Increment the array counter i++; // Extract the transaction items string liabilityItems = transactionTypes[i]; // Import all transaction types result.LiabilityTransactions.AddRange(LiabilityLogic.Import(liabilityItems, result.Configuration)); // All done break; case Headers.MemorizedTransactionList: // Increment the array counter i++; // Extract the transaction items string memItems = transactionTypes[i]; // Import all transaction types result.MemorizedTransactionListTransactions.AddRange(MemorizedTransactionListLogic.Import(memItems, result.Configuration)); // All done break; default: // Don't do any processing break; } } } return(result); }