Пример #1
0
        /// <summary>
        /// Create an account
        /// </summary>
        /// <param name="account">The account to create</param>
        public void Create(Account account)
        {
            IDbCommand command    = null;
            DaoSession daoSession = null;

            daoSession = this.GetContext();

            command = daoSession.CreateCommand(CommandType.Text);

            try
            {
                if (daoSession.DataSource.DbProvider.UseParameterPrefixInSql)
                {
                    command.CommandText = INSERT_ACCOUNT;
                }
                else
                {
                    command.CommandText = OLEDB_INSERT_ACCOUNT;
                }

                IDbDataParameter sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_ID;
                sqlParameter.Value         = account.Id;
                sqlParameter.DbType        = DbType.Int32;
                command.Parameters.Add(sqlParameter);

                sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_FIRSTNAME;
                sqlParameter.Value         = account.FirstName;
                sqlParameter.DbType        = DbType.String;
                sqlParameter.Size          = 32;
                command.Parameters.Add(sqlParameter);

                sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_LASTNAME;
                sqlParameter.Value         = account.LastName;
                sqlParameter.DbType        = DbType.String;
                sqlParameter.Size          = 32;
                command.Parameters.Add(sqlParameter);

                sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_EMAIL;
                sqlParameter.Value         = account.EmailAddress;
                sqlParameter.DbType        = DbType.String;
                sqlParameter.Size          = 128;
                command.Parameters.Add(sqlParameter);

                command.ExecuteNonQuery();

                command.Parameters.Clear();
            }
            catch (System.Exception e)
            {
                throw new DataAccessException("Error executing OracleAccountDao.Create. Cause :" + e.Message, e);
            }
            finally
            {
                command.Dispose();
            }
        }
Пример #2
0
        /// <summary>
        /// Get an account by his id.
        /// </summary>
        /// <param name="accountID">An account id.</param>
        /// <returns>An account.</returns>
        public Account GetAccountById(int accountID)
        {
            IDbCommand command    = null;
            DaoSession daoSession = null;
            Account    account    = null;

            daoSession = this.GetContext();

            command = daoSession.CreateCommand(CommandType.Text);

            try
            {
                if (daoSession.DataSource.DbProvider.UseParameterPrefixInSql)
                {
                    command.CommandText = SELECT_ACCOUNT_BY_ID;
                }
                else
                {
                    command.CommandText = OLEDB_SELECT_ACCOUNT_BY_ID;
                }

                IDbDataParameter sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_ID;
                sqlParameter.Value         = accountID;
                sqlParameter.DbType        = DbType.Int32;
                command.Parameters.Add(sqlParameter);

                IDataReader dataReader;

                dataReader = command.ExecuteReader();

                if (dataReader.Read())
                {
                    account = PopulateAccount(dataReader);
                }

                dataReader.Close();
                command.Parameters.Clear();
            }
            catch (System.Exception e)
            {
                throw new DataAccessException("Error executing OracleAccountDao.GetAccountById. Cause :" + e.Message, e);
            }
            finally
            {
                command.Dispose();
            }

            return(account);
        }
Пример #3
0
        /// <summary>
        /// Delete an account
        /// </summary>
        /// <param name="account">The account to delete</param>
        public void Delete(Account account)
        {
            IDbCommand command    = null;
            DaoSession daoSession = null;

            daoSession = this.GetContext();

            command = daoSession.CreateCommand(CommandType.Text);

            try
            {
                if (daoSession.DataSource.DbProvider.UseParameterPrefixInSql)
                {
                    command.CommandText = DELETE_ACCOUNT;
                }
                else
                {
                    command.CommandText = OLEDB_DELETE_ACCOUNT;
                }

                IDbDataParameter sqlParameter = command.CreateParameter();
                sqlParameter.ParameterName = PARAM_ACCOUNT_ID;
                sqlParameter.Value         = account.Id;
                command.Parameters.Add(sqlParameter);

                command.ExecuteNonQuery();

                command.Parameters.Clear();
            }
            catch (System.Exception e)
            {
                throw new DataAccessException("Error executing MySqlAccountDao.Delete. Cause :" + e.Message, e);
            }
            finally
            {
                command.Dispose();
            }
        }