예제 #1
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;
        }
예제 #2
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); }
           
        }