Пример #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();
            }
        }