示例#1
0
        /// <summary>
        /// Removes all accounts that are linked to the given bank
        /// </summary>
        public static void RemoveAllAccounts(int bankId)
        {
            BankdbContext      context  = new BankdbContext();
            List <BankAccount> accounts = context.BankAccount.Where(a => a.BankId == bankId).ToList();

            foreach (BankAccount a in accounts)
            {
                AccountHandling.RemoveAccount(a.Iban);
            }
            context.SaveChanges();
        }
示例#2
0
        /// <summary>
        /// Removes customer entity information
        /// </summary>
        public static void RemoveCustomer(int customerId)
        {
            BankdbContext context        = new BankdbContext();
            Customer      removeCustomer = context.Customer.Where(c => c.Id == customerId).FirstOrDefault();

            if (removeCustomer != null)
            {
                // First remove all accounts that are linked to the customer
                List <BankAccount> accounts = context.BankAccount.Where(a => a.CustomerId == customerId).ToListAsync().Result;
                foreach (BankAccount a in accounts)
                {
                    AccountHandling.RemoveAccount(a.Iban);
                }
                // Then remove customer
                context.Customer.Remove(removeCustomer);
                context.SaveChanges();
            }
        }
示例#3
0
        // Remove Bank entity information
        public static void RemoveBank(int bankId)
        {
            BankdbContext context = new BankdbContext();

            Models.Bank removeBank = context.Bank.Where(b => b.Id == bankId).SingleOrDefault();
            if (removeBank != null)
            {
                AccountHandling.RemoveAllAccounts(bankId);
                AccountHandling.ViewAllAccountsInOneBank(bankId);
                CustomerHandling.RemoveAllCustomers(bankId);
                CustomerHandling.ViewCustomersInBank(bankId);

                // Then remove the bank itself
                context.Bank.Remove(removeBank);
                context.SaveChanges();
                Console.WriteLine("Removed bank number {0}!\n", bankId);
            }
        }