private static void UpdateUsersLoanAmount() { Console.WriteLine("Select customer to update loan amount of:"); string selectedAccount = Console.ReadLine(); CustomersList customerList = new CustomersList(GetCustomers()); byte[] encryptedData = EncryptCustomerList(customerList); customerList = null; customerList = DecryptCustomerList(encryptedData); encryptedData = null; Customer customer = customerList.customers.FirstOrDefault(user => user.ID == selectedAccount); selectedAccount = null; if (customer != null) { Console.WriteLine($"Current loan amount is {customer.LoanRemaining}, please enter new loan amount"); string newLoanAmount = Console.ReadLine(); CustomersList customersListClone = customerList.Clone() as CustomersList; List <Customer> newCustomers = customersListClone.customers; customerList = null; Customer updatedCustomer = new Customer(customer.Address, customer.IBAN, newLoanAmount, customer.Password, customer.ID, customer.FirstName, customer.LastName, customer.EmailAddress); newLoanAmount = null; int indexOfTempCustomer = 0; newCustomers.ForEach(tempCustomer => { if (tempCustomer.ID == customer.ID) { indexOfTempCustomer = newCustomers.IndexOf(tempCustomer); } else { } }); customer = null; newCustomers[indexOfTempCustomer] = updatedCustomer; indexOfTempCustomer = 0; Console.WriteLine($"Current loan amount is {updatedCustomer.LoanRemaining}"); updatedCustomer = null; CustomersList updatedCustomers = new CustomersList(newCustomers); newCustomers = null; updateCSV(updatedCustomers.customers); updatedCustomers = null; GC.Collect(); Console.ReadKey(); } else { Console.WriteLine("Customer account does not exist"); Console.ReadKey(); } }
private static void DeleteUsersLoan() { CustomersList customerList = new CustomersList(GetCustomers()); byte[] encryptedData = EncryptCustomerList(customerList); customerList = null; customerList = DecryptCustomerList(encryptedData); encryptedData = null; CustomersList customersListClone = customerList.Clone() as CustomersList; customerList = null; List <Customer> newCustomers = customersListClone.customers; Console.WriteLine("Select customer whose loan youd like to delete:"); string selectedAccount = Console.ReadLine(); Customer customer = customersListClone.customers.FirstOrDefault(user => user.ID == selectedAccount); selectedAccount = null; if (customer != null) { newCustomers.Remove(customer); customer = null; CustomersList newCustomerList = new CustomersList(newCustomers); updateCSV(newCustomerList.customers); newCustomers = null; customersListClone = null; GC.Collect(); Console.ReadKey(); } else { Console.WriteLine("Customer account does not exist"); Console.ReadKey(); } customer = null; newCustomers = null; customersListClone = null; GC.Collect(); }
private static void AddNewUsersLoan() { CustomersList customerList = new CustomersList(GetCustomers()); byte[] encryptedData = EncryptCustomerList(customerList); customerList = null; customerList = DecryptCustomerList(encryptedData); encryptedData = null; CustomersList customersListClone = customerList.Clone() as CustomersList; customerList = null; List <Customer> newCustomers = customersListClone.customers; Console.WriteLine("Please enter users information"); string firstName = null; bool firstnameRegexMatch = false; while (firstnameRegexMatch == false) { Console.WriteLine("Please enter first name:"); firstName = removeCharacter(Console.ReadLine(), ","); var regex = new Regex(@"[a - zA - Z]{1,25}"); Match match = regex.Match(firstName); if (match.Success) { firstnameRegexMatch = true; } else { Console.WriteLine("Invalid first name"); firstnameRegexMatch = false; } } string lastName = null; bool lastNameRegexMatch = false; while (lastNameRegexMatch == false) { Console.WriteLine("Please enter last name:"); lastName = removeCharacter(Console.ReadLine(), ","); var regex = new Regex(@"[a-zA-Z]{1,25}"); Match match = regex.Match(lastName); if (match.Success) { lastNameRegexMatch = true; } else { Console.WriteLine("Invalid last name"); lastNameRegexMatch = false; } } string IBAN = null; bool IBANregexMatches = false; while (IBANregexMatches == false) { Console.WriteLine("Please enter IBAN:"); IBAN = removeCharacter(Console.ReadLine(), ","); var regex = new Regex(@"[a-zA-Z0-9]{18,34}"); Match match = regex.Match(IBAN); if (match.Success) { IBANregexMatches = true; } else { Console.WriteLine("Invalid IBAN"); IBANregexMatches = false; } } Console.WriteLine("Please enter address:"); string address = removeCharacter(Console.ReadLine(), ","); string email = null; bool emailRegexMatches = false; while (emailRegexMatches == false) { Console.WriteLine("Please enter email:"); email = removeCharacter(Console.ReadLine(), ","); var regex = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" + @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$"); Match match = regex.Match(email); if (match.Success) { emailRegexMatches = true; } else { Console.WriteLine("Invalid email"); emailRegexMatches = false; } } Console.WriteLine("Please enter loan balance:"); string loanAmount = removeCharacter(Console.ReadLine(), ","); Console.WriteLine("Please enter password:"******","); string id = (Convert.ToInt32(customersListClone.customers.LastOrDefault().ID) + 1).ToString(); Console.WriteLine($"id: {id}"); customersListClone = null; Customer newCustomer = new Customer(address, IBAN, loanAmount, password, id, firstName, lastName, email); newCustomers.Add(newCustomer); newCustomer = null; CustomersList newCustomerList = new CustomersList(newCustomers); newCustomers = null; updateCSV(newCustomerList.customers); newCustomerList = null; GC.Collect(); Console.ReadKey(); }