protected void SubmitClicked(object sender, ImageClickEventArgs e)
        {
            if (Page.IsValid) {

                string userId = WebComponents.CleanString.InputText(txtUserId.Text, 50);
                string password = WebComponents.CleanString.InputText(txtPassword.Text, 50);
                string email = WebComponents.CleanString.InputText(txtEmail.Text, 50);
                AddressInfo address = addr.Address;
                string language = prefs.Language;
                string favCategory = prefs.Category;
                bool showFavorites = prefs.IsShowFavorites;
                bool showBanners = prefs.IsShowBanners;

                // Store all the customers information in an account business entity
                AccountInfo accountInfo = new AccountInfo(userId, password, email, address, language, favCategory, showFavorites, showBanners);

                ProcessFlow.AccountController accountController = new ProcessFlow.AccountController();

                if (!accountController.CreateAccount(accountInfo)){

                    // Tell the user they have failed to create an account
                    valUserId.ErrorMessage = MSG_FAILURE;
                    valUserId.IsValid = false;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Insert a new account info the database
        /// </summary>
        /// <param name="acc">A thin data class containing all the new account information</param>
        public void Insert(AccountInfo acc)
        {
            SqlParameter[] signOnParms = GetSignOnParameters();
            SqlParameter[] accountParms = GetAccountParameters();
            SqlParameter[] profileParms = GetProfileParameters();

            signOnParms[0].Value = acc.UserId;
            signOnParms[1].Value = acc.Password;

            SetAccountParameters(accountParms, acc);
            SetProfileParameters(profileParms, acc);

            using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionString)) {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction()) {
                    try {
                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_INSERT_SIGNON, signOnParms);
                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_INSERT_ACCOUNT, accountParms);
                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_INSERT_PROFILE, profileParms);
                        trans.Commit();

                    }catch {
                        trans.Rollback();
                        throw;
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// A method to update an existing account
        /// </summary>
        /// <param name="account">An account entity with information about the account to be updated</param>
        public void Update(AccountInfo account)
        {
            // Validate input
            if (account.UserId.Trim() == string.Empty)
                return;

            // Get an instance of the account DAL using the DALFactory
            IAccount dal = PetShop.DALFactory.Account.Create();

            // Send the udpated account information to the DAL
            dal.Update(account);
        }
Example #4
0
        /// <summary>
        /// A method to insert a new Account
        /// </summary>
        /// <param name="account">An account entity with information about the new account</param>
        public void Insert(AccountInfo account)
        {
            // Validate input
            if (account.UserId.Trim() == string.Empty)
                return;

            // Get an instance of the account DAL using the DALFactory
            IAccount dal = PetShop.DALFactory.Account.Create();

            // Call the DAL to insert the account
            dal.Insert(account);
        }
Example #5
0
        public bool CreateAccount(AccountInfo newAccountInfo)
        {
            try {
                // Creata a new business logic tier
                Account account = new Account();

                // Call the insert method
                account.Insert(newAccountInfo);

                // Store the data in session state and store the authenticated cookie
                HttpContext.Current.Session[ACCOUNT_KEY] = newAccountInfo;
                FormsAuthentication.SetAuthCookie(newAccountInfo.UserId, false);

                //Finally forward to the welcome page
                HttpContext.Current.Response.Redirect(URL_ACCOUNTCREATE, true);

            }catch {
                return false;
            }

            return true;
        }
Example #6
0
        protected void SubmitClicked(object sender, ImageClickEventArgs e)
        {
            if (Page.IsValid) {

                ProcessFlow.AccountController accountController = new ProcessFlow.AccountController();

                // Retrieve the account information from the account controller
                AccountInfo myAccount = accountController.GetAccountInfo(true);

                // Merge in the changes
                string email = WebComponents.CleanString.InputText(txtEmail.Text, 50);
                AddressInfo address = addr.Address;
                string language = prefs.Language;
                string favCategory = prefs.Category;
                bool showFavorites = prefs.IsShowFavorites;
                bool showBanners = prefs.IsShowBanners;

                AccountInfo updatedAccountInfo = new AccountInfo(myAccount.UserId, myAccount.Password, email, address, language, favCategory, showFavorites, showBanners);

                // Submit the changes back to the controller
                accountController.UpdateAccount(updatedAccountInfo);
            }
        }
Example #7
0
 /// <summary>
 /// An internal function to bind values parameters 
 /// </summary>
 /// <param name="parms">Database parameters</param>
 /// <param name="acc">Values to bind to parameters</param>
 private void SetProfileParameters(SqlParameter[] parms, AccountInfo acc)
 {
     parms[0].Value = acc.Language;
     parms[1].Value = acc.Category;
     parms[2].Value = acc.IsShowFavorites;
     parms[3].Value = acc.IsShowBanners;
     parms[4].Value = acc.UserId;
 }
Example #8
0
 /// <summary>
 /// An internal function to bind values parameters 
 /// </summary>
 /// <param name="parms">Database parameters</param>
 /// <param name="acc">Values to bind to parameters</param>
 private void SetAccountParameters(SqlParameter[] parms, AccountInfo acc)
 {
     parms[0].Value = acc.Email;
     parms[1].Value = acc.Address.FirstName;
     parms[2].Value = acc.Address.LastName;
     parms[3].Value = acc.Address.Address1;
     parms[4].Value = acc.Address.Address2;
     parms[5].Value = acc.Address.City;
     parms[6].Value = acc.Address.State;
     parms[7].Value = acc.Address.Zip;
     parms[8].Value = acc.Address.Country;
     parms[9].Value = acc.Address.Phone;
     parms[10].Value = acc.UserId;
 }
Example #9
0
        /// <summary>
        /// Update an account in the database
        /// </summary>
        /// <param name="myAccount">Updated account parameters, you must supply all parameters</param>
        public void Update(AccountInfo myAccount)
        {
            SqlParameter[] accountParms = GetAccountParameters();
            SqlParameter[] profileParms = GetProfileParameters();

            SetAccountParameters(accountParms, myAccount);
            SetProfileParameters(profileParms, myAccount);

            using (SqlConnection conn = new SqlConnection(SQLHelper.ConnectionString)) {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction()) {
                    try {
                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_UPDATE_ACCOUNT, accountParms);
                        SQLHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_UPDATE_PROFILE, profileParms);
                        trans.Commit();
                    }catch {
                        trans.Rollback();
                        throw;
                    }
                }
            }
        }
Example #10
0
        /// <summary>
        /// A method to process an updated account
        /// </summary>
        /// <param name="updatedAccountInfo">Updated account information</param>
        public void UpdateAccount(AccountInfo updatedAccountInfo)
        {
            // Create the business logic tier
            Account account = new Account();

            // Call the udpate method
            account.Update(updatedAccountInfo);

            //Store the update info back in session state
            HttpContext.Current.Session[ACCOUNT_KEY] = updatedAccountInfo;

            //Redirect the user to the my account page
            HttpContext.Current.Response.Redirect(URL_ACCOUNTUPDATE, true);
        }