private bool SaveAccount() { string newUserName = UserName.Text.Trim(); if (Page.IsValid && ValidateNewUserName(newUserName)) { //UPDATE ACCOUNT SETTINGS _User.UserName = newUserName; _User.Email = Email.Text; _User.PrimaryAddress.Email = Email.Text; // PREVENT DISABLING OF YOUR OWN ACCOUNT if (_User.Id != AbleContext.Current.UserId) { _User.IsApproved = !IsDisabled.Checked; ShowHideDisabledAlert(); } // UPDATE AFFILIATE ASSOCIATION int affliateId = AlwaysConvert.ToInt(Affiliate.SelectedValue, 0); _User.Affiliate = AffiliateDataSource.Load(affliateId); _User.AffiliateReferralDate = LocaleHelper.LocalNow; // UPDATE TAX EXEMPTIONS _User.TaxExemptionType = (TaxExemptionType)AlwaysConvert.ToInt(TaxExemptionType.SelectedValue); _User.TaxExemptionReference = TaxExemptionReference.Text; // SAVE USER SETTINGS _User.Save(); return(true); } return(false); }
/// <summary> /// Checks the associated affiliate and resets the association /// if the referral is expired /// </summary> internal void ValidateAffiliate() { // ValidateAffiliate is called by Basket.Checkout and User.Save // We do not need to validate if affiliate is not set if (this.AffiliateId == 0) { return; } bool affiliateValid = false; Affiliate affiliate = this.Affiliate; if (affiliate != null) { int orderCount; DateTime referralExpiration; switch (affiliate.ReferralPeriod) { case AffiliateReferralPeriod.FirstOrder: // IF AFFILIATE ORDER HAS BEEN PLACED BY THIS CUSTOMER SINCE REFERRAL THE ASSOCIATION IS INVALID orderCount = AffiliateDataSource.GetOrderCountForUser(affiliate.AffiliateId, this.UserId, this.AffiliateReferralDate); affiliateValid = (orderCount == 0); break; case AffiliateReferralPeriod.NumberOfDays: // AFFILIATE ASSOCIATION IS ONLY VALID WITHIN A SET NUMBER OF DAYS referralExpiration = this.AffiliateReferralDate.AddDays(affiliate.ReferralDays); affiliateValid = (referralExpiration > LocaleHelper.LocalNow); break; case AffiliateReferralPeriod.FirstOrderWithinNumberOfDays: // AFFILIATE IS VALID IF WITHIN THE TIME PERIOD AND FIRST ORDER HAS NOT BEEN PLACED referralExpiration = this.AffiliateReferralDate.AddDays(affiliate.ReferralDays); orderCount = AffiliateDataSource.GetOrderCountForUser(affiliate.AffiliateId, this.UserId, this.AffiliateReferralDate); affiliateValid = (referralExpiration > LocaleHelper.LocalNow && orderCount == 0); break; case AffiliateReferralPeriod.Persistent: // AFFILIATE IS ALWAYS VALID affiliateValid = true; break; } } // IF AFFILIATE IS INVALID, MAKE SURE IT IS NOT SET FOR THIS USER if (!affiliateValid) { Database database = Token.Instance.Database; DbCommand command = database.GetSqlStringCommand("UPDATE ac_Users SET AffiliateId = NULL, AffiliateReferralDate = NULL WHERE UserId = @userId"); database.AddInParameter(command, "@userId", System.Data.DbType.Int32, this.UserId); database.ExecuteNonQuery(command); _AffiliateId = 0; _AffiliateReferralDate = DateTime.MinValue; _Affiliate = null; } }
protected void Page_Load(object sender, EventArgs e) { _AffiliateAccounts = UserDataSource.LoadUserAffiliateAccounts(AbleContext.Current.User.Id); //IF SELEF SIGNUP IS NOT ALLOWED AND AFFILIATE IS NOT REGISTERED THEN NO ACCESS TO THIS PAGE if (!AbleContext.Current.Store.Settings.AffiliateAllowSelfSignup && _AffiliateAccounts.Count == 0) { Response.Redirect("MyAccount.aspx"); } //IF NO EXISTING AFFILIATE ACCOUNT THEN ENABLE SIGNUP if (_AffiliateAccounts.Count == 0) { AffiliateForm1.Visible = true; AffiliateInfoPanel.Visible = false; } //IF HAVE REGISTED AFFILIATE ACCOUNTS THEN SHOW THEM IN DROPDOWN else { AffiliateForm1.Visible = false; AffiliateInfoPanel.Visible = true; trAffiliateReport.Visible = true; int affiliateId = 0; if (!Page.IsPostBack && _AffiliateAccounts.Count > 1) { AffiliateAccountList.DataSource = _AffiliateAccounts; AffiliateAccountList.DataBind(); trMultiAccounts.Visible = true; } else if (!Page.IsPostBack && _AffiliateAccounts.Count == 1) { _Affiliate = _AffiliateAccounts[0]; trMultiAccounts.Visible = false; } if (_AffiliateAccounts.Count > 1) { affiliateId = AlwaysConvert.ToInt(AffiliateAccountList.SelectedValue); _Affiliate = AffiliateDataSource.Load(affiliateId); } else if (_AffiliateAccounts.Count == 1) { _Affiliate = _AffiliateAccounts[0]; } if (!Page.IsPostBack && _Affiliate != null) { BindAffiliateReport(); } HiddenAffiliateId.Value = _Affiliate.Id.ToString(); } }
/// <summary> /// Initializes the user context for this token. /// </summary> /// <param name="context">The HttpContext to obtain the user data from</param> public void InitUserContext(HttpContext context) { //INITIALIZE THE TOKEN FOR THIS REQUEST if (context != null) { //GET THE USER CONTEXT HttpRequest request = context.Request; if (request.IsAuthenticated) { //FOR MULTISTORE, IF AUTHENTICATED MAKE SURE THE USER IS VALID FOR THE STORE _User = UserDataSource.LoadForUserName(context.User.Identity.Name); if ((_User == null) || (_User.StoreId != this.StoreId)) { //store mismatch, expire the forms ticket User.Logout(); //redirect to this page to start over context.Response.Redirect(request.RawUrl, true); } } else { _User = UserDataSource.LoadForUserName(request.AnonymousID, true); } // UPDATE LAST ACTIVITY DATE _User.LastActivityDate = LocaleHelper.LocalNow; // CHECK FOR AN AFFILIATE INDICATOR Affiliate affiliate = AffiliateDataSource.Load(AlwaysConvert.ToInt(context.Request.QueryString[Store.GetCachedSettings().AffiliateParameterName])); if (affiliate != null && affiliate.AffiliateId != _User.AffiliateId) { // A VALID AFFILIATE WAS PASSED AND IS NOT THE ONE ASSOCIATED WITH USER // SHOULD WE UPDATE THE USER? StoreSettingCollection settings = Store.GetCachedSettings(); if (settings.AffiliateReferralRule == ReferralRule.NewSignupsOrExistingUsersOverrideAffiliate || _User.AffiliateId == 0) { // THE RULE IS TO ALWAYS OVERRIDE // OR AN EXISTING USER WITH NO AFFILIATE SET WITH EXISTING USERS NO OVERRIDE OPTION // (IF IT WERE A NEW USER CREATED BY THIS REQUEST, AFFILIATEID WOULD ALREADY BE SET) // AFFILIATE SHOULD BE UPDATED FOR THE TARGET USER _User.AffiliateId = affiliate.AffiliateId; _User.AffiliateReferralDate = _User.LastActivityDate; } } this.UserId = _User.UserId; if (_User.UserId != 0) { _User.Save(); } } }
protected void Page_Init(object sender, EventArgs e) { User user = AbleContext.Current.User; Affiliate affiliate = AffiliateDataSource.Load(AlwaysConvert.ToInt(Request.QueryString["AffiliateId"])); if (affiliate == null || affiliate.Group == null || !user.IsInGroup(affiliate.GroupId)) { Response.Redirect("~/Members/MyAffiliateAccount.aspx"); } AffiliateForm.Affiliate = affiliate; }
protected void Page_Load(object sender, System.EventArgs e) { _AffiliateId = AlwaysConvert.ToInt(Request.QueryString["AffiliateId"]); _Affiliate = AffiliateDataSource.Load(_AffiliateId); if (_Affiliate == null) { Response.Redirect("Default.aspx"); } InstructionText.Text = string.Format(InstructionText.Text, AbleContext.Current.Store.Settings.AffiliateParameterName, _AffiliateId, GetHomeUrl()); if (!Page.IsPostBack) { InitEditForm(); } Caption.Text = string.Format(Caption.Text, _Affiliate.Name); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DateTime localNow = LocaleHelper.LocalNow; int currentYear = localNow.Year; for (int i = -10; i < 11; i++) { string thisYear = ((int)(currentYear + i)).ToString(); YearList.Items.Add(new ListItem(thisYear, thisYear)); } string tempDate = Request.QueryString["ReportDate"]; DateTime reportDate = localNow; if ((!string.IsNullOrEmpty(tempDate)) && (tempDate.Length == 8)) { try { int month = AlwaysConvert.ToInt(tempDate.Substring(0, 2)); int day = AlwaysConvert.ToInt(tempDate.Substring(2, 2)); int year = AlwaysConvert.ToInt(tempDate.Substring(4, 4)); reportDate = new DateTime(year, month, day); } catch { } } ViewState["ReportDate"] = reportDate; //BIND THE AFFILAITE LIST AffiliateList.DataSource = AffiliateDataSource.LoadAll("Name"); AffiliateList.DataBind(); //INITIALIZE AFFILIATE LIST int affiliateId = AlwaysConvert.ToInt(Request.QueryString["AffiliateId"]); ListItem listItem = AffiliateList.Items.FindByValue(affiliateId.ToString()); if (listItem != null) { AffiliateList.SelectedIndex = AffiliateList.Items.IndexOf(listItem); } //UPDATE DATE FILTER AND GENERATE REPORT UpdateDateFilter(); } }