Esempio n. 1
0
 public IEnumerable <AccountDTO> GetAllAccounts()
 {
     using (var context = new AccountsContext())
     {
         return((from a in context.Accounts select a).ToList());
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Adds bank account to the container
 /// </summary>
 /// <param name="account">Bank account</param>
 private void Add(DalBankAccount account)
 {
     using (var db = new AccountsContext())
     {
         db.Accounts.Add(account);
         db.SaveChanges();
     }
 }
Esempio n. 3
0
 public void Create(AccountDTO account)
 {
     using (var context = new AccountsContext())
     {
         context.Accounts.Add(account);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Closes bank account
        /// </summary>
        /// <param name="accountID">Bank account ID</param>
        private void Close(string accountID)
        {
            using (var db = new AccountsContext())
            {
                var closedAccount = db.Accounts.Where(p => p.BankAccountNumber == accountID).FirstOrDefault();

                if (closedAccount != null)
                {
                    closedAccount.IsClosed = true;

                    db.Entry(closedAccount).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Gets all bank accounts
        /// </summary>
        ///<returns>Collection of accounts</returns>
        public IEnumerable <DalBankAccount> GetAccounts()
        {
            List <DalBankAccount> dalBankAccounts = new List <DalBankAccount>();

            using (var db = new AccountsContext())
            {
                var query = db.Accounts.Include(p => p.AccountOwner).ToList();

                foreach (var account in query)
                {
                    dalBankAccounts.Add(account);
                }
            }

            return(dalBankAccounts);
        }
Esempio n. 6
0
        /// <summary>
        /// Finds bank account with specified ID
        /// </summary>
        /// <param name="accountID">Account ID</param>
        /// <returns>Reference to the bank account instance if bank account with specified account ID is presents
        /// in the container. Null otherwise</returns>
        public DalBankAccount FindAccountByID(string accountID)
        {
            using (var db = new AccountsContext())
            {
                var query = db.Accounts.Where(p => p.BankAccountNumber == accountID).Include(p => p.AccountOwner).ToList();

                if (query.Any() == true)
                {
                    return(query.First());
                }
                else
                {
                    return(null);
                }
            }
        }
Esempio n. 7
0
        public void SaveAccount(DalBankAccount account)
        {
            using (var db = new AccountsContext())
            {
                var savedAccount = db.Accounts.Where(p => p.BankAccountNumber == account.BankAccountNumber).FirstOrDefault();

                if (savedAccount != null)
                {
                    savedAccount.BonusScores   = account.BonusScores;
                    savedAccount.InvoiceAmount = account.InvoiceAmount;
                    savedAccount.IsClosed      = account.IsClosed;

                    db.Entry(savedAccount).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Esempio n. 8
0
 public void Withdraw(int accountID, decimal amount)
 {
     using (var context = new AccountsContext())
     {
         try
         {
             var account = (from a in context.Accounts
                            where a.AccountID == accountID
                            select a).Single();
             account.Balance -= amount;
             context.SaveChanges();
         }
         catch (InvalidOperationException)
         {
             // Ignore
         }
     }
 }
Esempio n. 9
0
 public void Remove(int accountID)
 {
     using (var context = new AccountsContext())
     {
         try
         {
             var account = (from a in context.Accounts
                            where a.AccountID == accountID
                            select a).Single();
             context.Accounts.Remove(account);
             context.SaveChanges();
         }
         catch (InvalidOperationException)
         {
             // Ignore
         }
     }
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EFAccountsRepository"/> class.
 /// </summary>
 /// /<param name="context">EF context class for accounts.</param>
 public EFAccountsRepository(AccountsContext context)
 {
     this.context = context;
 }