Ejemplo n.º 1
0
        /// <summary>
        /// Get all accounts
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<Account> GetAllAccounts()
        {
            try
            {
                
                aDBE = new AccountDatabaseEntities();

                ObservableCollection<Account>converted  = new ObservableCollection<Account>();

                var accounts = from q in aDBE.Accounts
                              select q;


                foreach (Accounts p in accounts)
                {
                    Account acc = new Account(p.AccountNr, p.AccountName, p.AccountBank, p.AccountBalance);
                    converted.Add(acc);
                }

                Console.WriteLine("Get accounts => " + converted.Count);
                return converted;
                
            }

            catch (Exception ex) { Console.WriteLine("Exception ADD => " + ex.Message); }
            finally { aDBE.Dispose(); }

            return null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add new account
        /// </summary>
        /// <param name="account">Account account</param>
        /// <returns>Boolean</returns>
        public Boolean AddNewAccount(Account account)
        {

            try
            {
                if (!AccountNrExist(account.AccountNr))
                {
                    aDBE = new AccountDatabaseEntities();

                    var t = new Accounts
                    {
                        AccountNr = account.AccountNr,
                        AccountName = account.AccountName,
                        AccountBank = account.AccountBank,
                        AccountBalance = account.AccountBalance
                    };

                    aDBE.Accounts.Add(t);
                    aDBE.SaveChanges();

                    Console.WriteLine("Created account => " + account.AccountNr);
                    return true;
                }
            }


            

            catch (Exception ex)
            {
                Console.WriteLine("Exception " + ex.Message);
            }

            finally
            {
                aDBE.Dispose();
            }

            

            return false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete account.
        /// </summary>
        /// <param name="account"></param>
        public void DeleteAccount(Account account)
        {
            try
            {
                if (AccountNrExist(account.AccountNr))
                {
                    aDBE = new AccountDatabaseEntities();

                    var query = from p in aDBE.Accounts
                                where p.AccountNr == account.AccountNr
                                select p;

                    foreach (var q in query)
                    {
                        aDBE.Accounts.Remove(q);
                    }
                    aDBE.SaveChanges();

                    
                }
            }

            catch (Exception ex) { Console.WriteLine("Exception Delete " + ex.Message); }
           
        }