示例#1
0
 public static AllCustomers Instance()
 {
     if (instance == null)
     {
         instance = new AllCustomers();
     }
     return(instance);
 }
示例#2
0
        public Account GetAccount(string accountNumber)
        {
            AllCustomers   instance = AllCustomers.Instance();
            List <Account> accounts = new List <Account>();
            Account        account  = null;

            foreach (var item in instance.Customers)
            {
                foreach (var acc in item.Accounts)
                {
                    if (acc.AccountNumber == accountNumber)
                    {
                        account = acc;
                    }
                }
            }
            // Tips på hur jag kan one-lina båda foreach-looparna uppskattas.
            // Account account = instance.Customers.Select(c => c.Accounts.FirstOrDefault(x => x.AccountNumber == accountNumber)).FirstOrDefault();

            return(account);
        }
示例#3
0
        public static void SetUpCusomer()
        {
            AllCustomers instace = AllCustomers.Instance();

            instace.Customers.Add(
                new Customer()
            {
                Id       = 1,
                Name     = "Thomas",
                Accounts = new List <Account>()
                {
                    new Account()
                    {
                        AccountNumber = "123-4",
                        Amount        = 100
                    },
                    new Account()
                    {
                        AccountNumber = "123-1",
                        Amount        = 200
                    }
                }
            });

            instace.Customers.Add(
                new Customer()
            {
                Id       = 2,
                Name     = "Micke",
                Accounts = new List <Account>()
                {
                    new Account()
                    {
                        AccountNumber = "123-2",
                        Amount        = 13123
                    },
                    new Account()
                    {
                        AccountNumber = "123-3",
                        Amount        = 43
                    }
                }
            });

            instace.Customers.Add(
                new Customer()
            {
                Id       = 3,
                Name     = "Markus",
                Accounts = new List <Account>()
                {
                    new Account()
                    {
                        AccountNumber = "123-5",
                        Amount        = 10000
                    },
                    new Account()
                    {
                        AccountNumber = "123-6",
                        Amount        = 5124
                    }
                }
            });

            instace.Customers.Add(
                new Customer()
            {
                Id       = 4,
                Name     = "Jocke",
                Accounts = new List <Account>()
                {
                    new Account()
                    {
                        AccountNumber = "123-7",
                        Amount        = 23
                    },
                    new Account()
                    {
                        AccountNumber = "123-8",
                        Amount        = 1515
                    }
                }
            });
        }