/// <summary> /// Submit Button Click Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { ZNode.Libraries.Admin.AccountAdmin _UserAccountAdmin = new ZNode.Libraries.Admin.AccountAdmin(); ZNode.Libraries.DataAccess.Entities.Account _UserAccount = new Account(); if (AccountID > 0) { _UserAccount = _UserAccountAdmin.GetByAccountID(AccountID); } if (AccountID == 0) { _UserAccount.CreateDte = System.DateTime.Now; } if (lstReferral.SelectedIndex != -1) { _UserAccount.ReferralCommissionTypeID = Convert.ToInt32(lstReferral.SelectedValue); } if (Discount.Text != "") { _UserAccount.ReferralCommission = Convert.ToDecimal(Discount.Text); discountAmount = Convert.ToDecimal(Discount.Text); } _UserAccount.TaxID = txtTaxId.Text; bool Check = false; if(AccountID >0) { //set update date _UserAccount.UpdateDte = System.DateTime.Now; Check = _UserAccountAdmin.Update(_UserAccount); } else { Check = _UserAccountAdmin.Insert(_UserAccount); } //Check Boolean Value if (Check) { Response.Redirect("~/admin/secure/sales/Affiliates/View.aspx"); } else { lblErrorMsg.Text = ""; } }
/// <summary> /// Submit Button Click Event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { ZNode.Libraries.Admin.AccountAdmin _UserAccountAdmin = new ZNode.Libraries.Admin.AccountAdmin(); ZNode.Libraries.DataAccess.Entities.Account _UserAccount = new Account(); if (AccountID > 0) { _UserAccount = _UserAccountAdmin.GetByAccountID(AccountID); } if (AccountID == 0) { _UserAccount.CreateDte = System.DateTime.Now; } //Set user's address _UserAccount.BillingFirstName = txtBillingFirstName.Text; _UserAccount.BillingLastName = txtBillingLastName.Text; _UserAccount.BillingCompanyName = txtBillingCompanyName.Text; _UserAccount.BillingStreet = txtBillingStreet1.Text; _UserAccount.BillingStreet1 = txtBillingStreet2.Text; _UserAccount.BillingCity = txtBillingCity.Text; _UserAccount.BillingStateCode = txtBillingState.Text; _UserAccount.BillingPostalCode = txtBillingPostalCode.Text; _UserAccount.BillingPhoneNumber = txtBillingPhoneNumber.Text; _UserAccount.BillingEmailID = txtBillingEmail.Text; _UserAccount.EmailOptIn = chkOptIn.Checked; if (lstBillingCountryCode.SelectedIndex != -1) { _UserAccount.BillingCountryCode = lstBillingCountryCode.SelectedValue; } // Get Shipping field values _UserAccount.ShipFirstName = txtShippingFirstName.Text; _UserAccount.ShipLastName = txtShippingLastName.Text; _UserAccount.ShipCompanyName = txtShippingCompanyName.Text; _UserAccount.ShipStreet = txtShippingStreet1.Text; _UserAccount.ShipStreet1 = txtShippingStreet2.Text; _UserAccount.ShipCity = txtShippingCity.Text; _UserAccount.ShipStateCode = txtShippingState.Text; _UserAccount.ShipPostalCode = txtShippingPostalCode.Text; if (lstShippingCountryCode.SelectedIndex != -1) { _UserAccount.ShipCountryCode = lstShippingCountryCode.SelectedValue; } _UserAccount.ShipPhoneNumber = txtShippingPhoneNumber.Text; _UserAccount.ShipEmailID = txtShippingEmail.Text; //Set Account Details _UserAccount.ExternalAccountNo = txtExternalAccNumber.Text.Trim(); _UserAccount.Description = txtDescription.Text; _UserAccount.CompanyName = txtCompanyName.Text; _UserAccount.Website = txtWebSite.Text.Trim(); _UserAccount.Source = txtSource.Text.Trim(); // Referral Detail if (lstReferral.SelectedIndex != -1) { _UserAccount.ReferralCommissionTypeID = Convert.ToInt32(lstReferral.SelectedValue); } if (Discount.Text != "" && Convert.ToDecimal(Discount.Text)>0) { _UserAccount.ReferralCommission = Convert.ToDecimal(Discount.Text); discountAmount = Convert.ToDecimal(Discount.Text); } ToggleDiscountValidator(); _UserAccount.TaxID = txtTaxId.Text; if (lstReferralStatus.SelectedValue == "I") { _UserAccount.ReferralStatus = "I"; } else if (lstReferralStatus.SelectedValue == "A") { _UserAccount.ReferralStatus = "A"; } else if (lstReferralStatus.SelectedValue == "N") { _UserAccount.ReferralStatus = "N"; } else { _UserAccount.ReferralStatus = ""; } if (ListProfileType.SelectedIndex != -1) { _UserAccount.ProfileID = int.Parse(ListProfileType.SelectedValue); } _UserAccount.AccountProfileCode = DBNull.Value.ToString(); _UserAccount.UpdateUser = System.Web.HttpContext.Current.User.Identity.Name; _UserAccount.UpdateDte = System.DateTime.Now; _UserAccount.UserID = _UserAccount.UserID; _UserAccount.AccountID = AccountID; _UserAccount.PortalID = int.Parse(ZNodeConfigManager.SiteConfig.PortalID.ToString()); //Custom Information Section _UserAccount.Custom1 = txtCustom1.Text.Trim(); _UserAccount.Custom2 = txtCustom2.Text.Trim(); _UserAccount.Custom3 = txtCustom3.Text.Trim(); try { if (_UserAccount.UserID.HasValue) { //get the User associated with the specified Unique identifier MembershipUser user = Membership.Providers["ZNodeAdminMembershipProvider"].GetUser(_UserAccount.UserID.Value, false); user.Email = txtBillingEmail.Text.Trim(); //Update the database with the Email Id for the specified user Membership.UpdateUser(user); if (Password.Text.Length > 0) { string passwordAnswer = Answer.Text.Trim(); if (passwordAnswer.Length == 0) { //Display error message lblAnswerErrorMsg.Text = " * Enter security answer"; lblErrorMsg.Text = " * Enter security answer"; return; } //Update new password user.ChangePassword(user.ResetPassword(), Password.Text.Trim()); //Log password for further debugging ZNodeUserAccount.LogPassword((Guid)user.ProviderUserKey, Password.Text.Trim()); //change password question and answer user.ChangePasswordQuestionAndAnswer(Password.Text.Trim(), ddlSecretQuestions.SelectedItem.Text, Answer.Text.Trim()); } //retrieve roles associated with this user string[] roles = Roles.GetRolesForUser(user.UserName); //Loop through the roles foreach (string Role in roles) { //Unassign this user from that role Roles.RemoveUserFromRole(user.UserName, Role); } //Loop thorugh the roles checkbox list foreach (ListItem li in RolesCheckboxList.Items) { if (li.Selected) { //Associate the User with the selected role Roles.AddUserToRole(user.UserName, li.Text); } } } else { if (UserID.Text.Trim().Length > 0) { string errorMessage = ""; //Check password field if (Password.Text.Trim().Length == 0) { errorMessage = " * Enter password <br />"; lblPwdErrorMsg.Text = " * Enter password"; } //check security answer field if (Answer.Text.Trim().Length == 0) { errorMessage += " * Enter security answer"; lblAnswerErrorMsg.Text = " * Enter security answer"; } //Show error message if (errorMessage.Length > 0) { lblErrorMsg.Text = errorMessage; return; } MembershipUser user = Membership.GetUser(UserID.Text.Trim()); if (user == null) //online account DOES NOT exist { ZNodeLogging log = new ZNodeLogging(); MembershipCreateStatus status = MembershipCreateStatus.ProviderError; log.LogActivityTimerStart(); MembershipUser newUser = Membership.CreateUser(UserID.Text.Trim(), Password.Text.Trim(), txtBillingEmail.Text.Trim(), ddlSecretQuestions.SelectedItem.Text, Answer.Text.Trim(), true, out status); if (status == MembershipCreateStatus.Success) { log.LogActivityTimerEnd((int)ZNodeLogging.ErrorNum.LoginCreateSuccess, UserID.Text.Trim()); //Log password for further debugging ZNodeUserAccount.LogPassword((Guid)newUser.ProviderUserKey, Password.Text.Trim()); //Update provider user key _UserAccount.UserID = new Guid(newUser.ProviderUserKey.ToString()); //Associate this user with the selected role foreach (ListItem li in RolesCheckboxList.Items) { if (li.Selected) { //Associate the User with the selected role Roles.AddUserToRole(newUser.UserName, li.Text); } } } else { log.LogActivityTimerEnd((int)ZNodeLogging.ErrorNum.LoginCreateFailed, UserID.Text.Trim()); lblErrorMsg.Text = "Unable to create online account. Please try again."; return; } } else { lblErrorMsg.Text = "User Id already exists. Please use differnet user id."; return; } } } } catch (Exception exception) { lblErrorMsg.Text = exception.Message; return; } bool Check = false; if(AccountID >0) { //set update date _UserAccount.UpdateDte = System.DateTime.Now; Check = _UserAccountAdmin.Update(_UserAccount); } else { Check = _UserAccountAdmin.Insert(_UserAccount); } //Check Boolean Value if (Check) { Response.Redirect("~/admin/secure/sales/customers/list.aspx"); } else { lblErrorMsg.Text = ""; } }