Пример #1
0
        public int CreateAccount(Account a)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewAccount";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("ContactID", a.ContactID);
                        cmd.Parameters.AddWithValue("CustomerID", a.CustomerID);
                        cmd.Parameters.AddWithValue("AccountTypeID", a.AccountTypeID);
                        cmd.Parameters.AddWithValue("BankingID", a.BankID);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
Пример #2
0
        // Creates an account
        public int create(int accountTypeID, int bankID, int customerID, int contactID)
        {
            // Establishes model
            AccountModel accountModel = new AccountModel();

            // Holds the new account
            Account newAccount = new Account();
            Account_Type accountType = new Account_Type();
            Bank newBank = new Bank();

            // Stored details for the account
            newAccount.CustomerID = customerID;
            newAccount.ContactID = contactID;
            newAccount.AccountTypeID = accountTypeID;
            newAccount.BankID = bankID;

            // Creates the account
            int accountID = accountModel.CreateAccount(newAccount);

            // Returns accountID
            return accountID;
        }
Пример #3
0
        public void EditAccount(Account a)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "EditAccount";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("AccountID", a.ID);
                        cmd.Parameters.AddWithValue("ContactID", a.ContactID);
                        cmd.Parameters.AddWithValue("CustomerID", a.CustomerID);
                        cmd.Parameters.AddWithValue("AccountTypeID", a.AccountTypeID);
                        cmd.Parameters.AddWithValue("BankingID", a.BankID);

                        cmd.ExecuteNonQuery();

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
        }
Пример #4
0
        // Gets a list of accounts for a customer speicifed in the customer object.
        public List<Account> SearchAccounts(Customer c)
        {
            var accountList = new List<Account>();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "SearchAccount";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    cmd.Parameters.AddWithValue("CustomerID", c.ID);
                    cmd.Parameters.AddWithValue("AccountID", null);
                    cmd.Parameters.AddWithValue("ContactID", null);
                    cmd.Parameters.AddWithValue("AccountTypeID", null);
                    cmd.Parameters.AddWithValue("BankingID", null);

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var a = new Account();
                        a.ID = int.Parse(reader["Account_ID"].ToString());
                        a.ContactID = int.Parse(reader["Contact_ID"].ToString());
                        a.CustomerID = int.Parse(reader["Customer_ID"].ToString());
                        a.AccountTypeID = int.Parse(reader["Account_Type_ID"].ToString());
                        a.BankID = int.Parse(reader["Banking_ID"].ToString());

                        accountList.Add(a);
                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return accountList;
            }
        }
Пример #5
0
 // Gets a list of account on elements specified in the account object.
 public List<Account> SearchAccounts(Account a)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 public Account SearchAccount(Account a)
 {
     return SearchAccount(a.ID);
 }