public void AddNewAccount(Customer customer) { var acc = new Account(this) { CustomerId = customer.Id }; ListOfAccounts.Add(acc); customer.Accounts.Add(acc); }
public void DeleteCustomer(Customer customer) { var checkSumOfAccounts = ListOfAccounts.Where(x => x.CustomerId == customer.Id).Select(y => y.Balance).Sum(); if (checkSumOfAccounts == 0) { ListOfAccounts.Remove(customer.Accounts.FirstOrDefault()); ListOfCustomers.Remove(customer); Output.GreenColor($"Borttaget kundnummer: {customer.Id}"); } else { Output.RedColor("Det går inte att ta bort en kund som har saldo större en noll på något av sina konton."); } }
public void AddNewCustomer(Customer customer) { ListOfCustomers.Add(new Customer(this) { Name = customer.Name, Adress = customer.Adress, City = customer.City, Country = customer.Country, ZipCode = customer.ZipCode, Region = customer.Region, OrganisationNumber = customer.OrganisationNumber, Telephone = customer.Telephone, }); // Add account to new customer AddNewAccount(ListOfCustomers.Last()); Console.WriteLine($"Ny kund skapad med kundnummer: {ListOfCustomers.Last().Id}"); Console.WriteLine($"Nytt kontonummer: {ListOfAccounts.Last().Id}"); }
public void DeleteAccount(Account account) { // Check sum of accounts var checkSumOfAccounts = ListOfAccounts.Where(x => x.Id == account.Id).Select(y => y.Balance).Sum(); // Count accounts var countAccounts = ListOfAccounts.Count(x => x.CustomerId == account.CustomerId); var customer = ListOfCustomers.FirstOrDefault(x => x.Id == account.CustomerId); // Can not delete account if sum is not zero or there is only one account // (customer always need an account) if (checkSumOfAccounts == 0 && countAccounts > 1) { ListOfAccounts.Remove(account); customer.Accounts.Remove(account); Output.GreenColor($"Borttaget kontonummer: {account.Id}"); } else { Output.RedColor("Kan ej ta bort kontot om:\n- det finns saldo\n- det är kundens enda konto"); } }
public Account GetSingleAccount(int id) { var selected = ListOfAccounts.SingleOrDefault(x => x.Id == id); return(selected); }