protected void btnLookUp_Click(object sender, EventArgs e) { try { HarperMembershipService.BaseResponse response = MembershipClient.GetMemberBySFGId(Cryptography.Hash(txtMemberId.Text.Trim().Replace("-", "").Replace(" ", ""), true)); MemberResponse = response.TypedResponse as HarperMembershipService.GetMemberResponse; string sfg_zip = MemberResponse.MemberData.Address.PostalCode; if (sfg_zip.Contains("-")) { sfg_zip = sfg_zip.Split('-')[0]; } string mbr_zip = txtZip.Text.Trim(); if (mbr_zip.Contains("-")) { mbr_zip = mbr_zip.Split('-')[0]; } if (sfg_zip == mbr_zip && MemberResponse.MemberData.MemberId.Length > 0) { Session["MemberId"] = Cryptography.Hash(MemberResponse.MemberData.MemberId, true); Session["Zip"] = Cryptography.Hash(txtZip.Text.Trim().Replace("-", "").Replace(" ", ""), true); Response.Redirect("UserConfirm.aspx", false); } else { SetError(new Exception("Zip code doesn't match or SFG id is empty")); } } catch (Exception ex) { SetError(ex); } }
protected void PopulateForm() { try { HarperMembershipService.BaseResponse response = MembershipClient.GetMemberBySFGId(Cryptography.Hash(CustomerID, true)); MemberResponse = response.TypedResponse as HarperMembershipService.GetMemberResponse; Session["MemberResponse"] = MemberResponse; if (!MemberResponse.WebAccountFound || CustomerID == "10001636220")//the check on customer id (mcoupland) was put in so Agatha could step through the process and style the pages { lblPassport.Text = MemberResponse.MemberData.MemberId; lblFirstName.Text = MemberResponse.MemberData.FirstName; lblLastName.Text = MemberResponse.MemberData.LastName; lblAddress1.Text = MemberResponse.MemberData.Address.Address1; lblAddress2.Text = MemberResponse.MemberData.Address.Address2; lblCity.Text = MemberResponse.MemberData.Address.City; lblZip.Text = MemberResponse.MemberData.Address.PostalCode; } else { SetError(new Exception(string.Format("Unable to create username. Member id {0} already has a username at SFG.", MemberResponse.MemberData.MemberId))); lblMessage.Text = string.Format("We encountered an error while trying to create your username.<br />{0}<br /><br />{1}", new object[] { "A user account has already been created for this member number.", Resources.GlobalStrings.ContactUs }); lblMessage.Visible = true; } } catch (Exception e) { SetError(e); } }
protected void btnSumbit_click(object sender, EventArgs e) { try { #region Unable to decode referral id, try finding original referral based on email address if (badReferralId) { try { Referral badRef = new Referral(email_address.Text); if (badRef.id > 0) { referralid = badRef.id; } else { throw new Exception(); } } catch (Exception ex) { logService.LogAppEvent("", @"HarperNET", "Referral", "Unable to link email to referral id (id could not be decoded and email not on file). Using default referrer. Referral id in url: " + Request["ReferralId"] + ", email address entered: " + email_address.Text, ex.Message, ex.StackTrace, "", "Page_Load"); Referral defaultReferral = new Referral(); defaultReferral.keycode = "POTRIAL"; defaultReferral.pubcode = "PO"; ReferralOffer offer = new ReferralOffer(defaultReferral.keycode, defaultReferral.pubcode); defaultReferral.ccmember = false; defaultReferral.datecreated = DateTime.Now; defaultReferral.dateexpires = defaultReferral.datecreated.AddMonths(offer.offerexpiresmonths); defaultReferral.friendemail = email_address.Text; defaultReferral.friendname = first_name.Text + " " + last_name.Text; HarperLINQ.tbl_Customer defaultReferrer = new tbl_Customer(ConfigurationManager.AppSettings["default_referrer_username"], true); defaultReferral.memberid = defaultReferrer.cusID; defaultReferral.subscriptionlength = offer.triallengthinmonths; defaultReferral.Save(); referralid = defaultReferral.id; } } #endregion HarperMembershipService.BaseResponse response = new HarperMembershipService.BaseResponse(); HarperMembershipService.MembershipService webservice = new HarperMembershipService.MembershipService(); #region Get selected region country = ddlCountries.SelectedValue; ISO3166 iso = new ISO3166(country, IdentifierType.Country_Code_Alpha2); string sfgcountrycode = iso.SFGCode; if (txtRegion.Text != "" && txtRegion.Text != null) { region = txtRegion.Text; } else if (txtRegionNotListed.Text != "" && txtRegionNotListed.Text != null) { region = txtRegionNotListed.Text; } else { region = ddlRegion.SelectedValue; } #endregion string erefid = Cryptography.EncryptData(referralid.ToString()); string epwd = Cryptography.EncryptData(txtPassword.Text); #region Redeem the referral response = webservice.RedeemReferral(erefid, first_name.Text, last_name.Text, email_address.Text, sfgcountrycode, address_line_1.Text, address_line_2.Text, city.Text, region, postal.Text, true, txtUserName.Text, epwd); #endregion #region Check for errors if (response == null) { throw new Exception(string.Format("Error redeeming referral id {0}, response from SFG was null.", referralid)); } if (response.Messages != null && response.Messages.Count() > 0) { throw new Exception(response.Messages[0].AhMessage); } #endregion Response.Redirect("~/Referral/RedemptionConfirmation.aspx", false); } catch (Exception ex) { logService.LogAppEvent("", @"HarperNET", "Referral", "Error in btnSumbit_click", ex.Message, ex.StackTrace, "", "btnSubmit_click"); LiteralControl err = new LiteralControl(); err.Text = "<p class=\"error-message\">An error has occurred. Please contact the membership department at <a href=\"mailto:[email protected]\">[email protected]</a></p>"; lblErrorMessage.Controls.Add(err); lblErrorMessage.Visible = true; } }
protected void btnSubmit_click(object sender, EventArgs e) { try { buildEmailList(); List <string> errorMessages = new List <string>(); //The error messages to log to the error db List <string> failedReferrals = new List <string>(); //The error messages to display on the confirmation page if some friends were added and some failed List <string> goodReferrals = new List <string>(); //Referral Ids of the successful referrals System.Text.RegularExpressions.Regex emlregex = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"); foreach (string[] email in emailsToRefer) { if (!emlregex.IsMatch(email[0])) { LiteralControl err = new LiteralControl(); err.Text = string.Format("<p class=\"error-message\">{0} is not a valid email address.</p>", email[0]); lblErrorMessage.Controls.Add(err); errorMessages.Add(err.Text); failedReferrals.Add(string.Format("{0} is not a valid email address.", email[0])); } else { string s1 = Cryptography.EncryptData(memberId); HarperMembershipService.BaseResponse response = webService.CreateReferral(s1, donor_name.Text, memberEmail, keyCode, pubCode, email[1], email[0], chk_cc_donor.Checked); HarperMembershipService.ReferralResponse typedresponse = (HarperMembershipService.ReferralResponse)response.TypedResponse; if (typedresponse == null || !typedresponse.Success) { string replacementMessage = string.Empty; string failedReferral = string.Format("We were unable to refer: {0}", email[1]); foreach (HarperMembershipService.Message msg in response.Messages) { LiteralControl err = new LiteralControl(); err.Text = string.Format("<p class=\"error-message\">{0}</p>", msg.AhMessage); lblErrorMessage.Controls.Add(err); errorMessages.Add(err.Text); //replace standard message with text appropriate for display when some failed and some did not switch (msg.AhMessage) { case "The person you referred is already a current Andrew Harper member. Please enter information for others you would like to refer for a complimentary membership.": case "This referral offer is available only to new members.": replacementMessage = string.Format("{0} is already a current Andrew Harper member.", email[1]); break; case "Another member has already referred your friend to Andrew Harper. Please enter information for others you would like to refer for a complimentary membership.": replacementMessage = string.Format("Another member has already referred {0} to Andrew Harper.", email[1]); break; default: replacementMessage = "An error has occurred."; break; } } failedReferrals.Add(replacementMessage); } else { goodReferrals.Add(typedresponse.referralid.ToString()); } } } #region create encrypted query string for good referral ids string referralids = string.Empty; foreach (string goodReferral in goodReferrals) { referralids += string.Format("{0}|", HarperCRYPTO.Cryptography.EncryptData(goodReferral)); } if (referralids.LastIndexOf("|") >= 0) { referralids = Server.UrlEncode(referralids.Substring(0, referralids.LastIndexOf("|"))); } #endregion #region no errors - redirect if (failedReferrals.Count() == 0) { Response.Redirect(string.Format("~/Referral/confirmation.aspx?Referrals={0}", referralids), false); } #endregion #region no successful referrals else if (failedReferrals.Count() == emailsToRefer.Count) { lblErrorMessage.Visible = true; } #endregion #region some successful referrals, some errors - redirect else { string err = string.Empty; foreach (string failedReferral in failedReferrals) { err += string.Format("{0}|", failedReferral); } err = Server.UrlEncode(err.Substring(0, err.LastIndexOf("|"))); string url = string.Format("~/Referral/confirmation.aspx?Referrals={0}&Errors={1}", new object[] { referralids, err }); Response.Redirect(url, false); } #endregion } catch (Exception ex) { try { logService.LogAppEvent("", @"HarperNET", "Referral", "Error in btnSubmit_click", ex.Message, ex.StackTrace, "", "btnSubmit_click"); } catch { } LiteralControl err = new LiteralControl(); err.Text = "<p class=\"error-message\">An error has occurred. Please contact the membership department at <a href=\"[email protected]\">[email protected]</a></p>"; lblErrorMessage.Controls.Add(err); lblErrorMessage.Visible = true; } }
protected void btnSumbit_click(object sender, EventArgs e) { try { #region Unable to decode referral id, try finding original referral based on email address if (badReferralId) { try { Referral badRef = new Referral(email_address.Text); if (badRef.id > 0) { referralid = badRef.id; } else { throw new Exception(); } } catch (Exception ex) { logService.LogAppEvent("", @"HarperNET", "Referral", "Unable to link email to referral id (id could not be decoded and email not on file). Using default referrer. Referral id in url: " + Request["ReferralId"] + ", email address entered: " + email_address.Text, ex.Message, ex.StackTrace, "", "Page_Load"); Referral defaultReferral = new Referral(); defaultReferral.keycode = "POTRIAL"; defaultReferral.pubcode = "PO"; ReferralOffer offer = new ReferralOffer(defaultReferral.keycode, defaultReferral.pubcode); defaultReferral.ccmember = false; defaultReferral.datecreated = DateTime.Now; defaultReferral.dateexpires = defaultReferral.datecreated.AddMonths(offer.offerexpiresmonths); defaultReferral.friendemail = email_address.Text; defaultReferral.friendname = first_name.Text + " " + last_name.Text; HarperLINQ.tbl_Customer defaultReferrer = new tbl_Customer(ConfigurationManager.AppSettings["default_referrer_username"], true); defaultReferral.memberid = defaultReferrer.cusID; defaultReferral.subscriptionlength = offer.triallengthinmonths; defaultReferral.Save(); referralid = defaultReferral.id; } } #endregion HarperMembershipService.BaseResponse response = new HarperMembershipService.BaseResponse(); HarperMembershipService.MembershipService webservice = new HarperMembershipService.MembershipService(); #region Get selected region country = ddlCountries.SelectedValue; ISO3166 iso = new ISO3166(country, IdentifierType.Country_Code_Alpha2); string sfgcountrycode = iso.SFGCode; if (txtRegion.Text != "" && txtRegion.Text != null) { region = txtRegion.Text; } else if (txtRegionNotListed.Text != "" && txtRegionNotListed.Text != null) { region = txtRegionNotListed.Text; } else { region = ddlRegion.SelectedValue; } #endregion string erefid = Cryptography.EncryptData(referralid.ToString()); string epwd = Cryptography.EncryptData(txtPassword.Text); #region Redeem the referral response = webservice.RedeemReferral(erefid, first_name.Text, last_name.Text, email_address.Text, sfgcountrycode, address_line_1.Text, address_line_2.Text, city.Text, region, postal.Text, true, txtUserName.Text, epwd); #endregion #region Check for errors if (response == null) { throw new Exception(string.Format("Error redeeming referral id {0}, response from SFG was null.", referralid)); } if (response.Messages != null && response.Messages.Count() > 0) { throw new Exception(response.Messages[0].AhMessage); } #endregion Response.Redirect("~/Referral/RedemptionConfirmation.aspx", false); } catch (Exception ex) { logService.LogAppEvent("", @"HarperNET", "Referral", "Error in btnSumbit_click", ex.Message, ex.StackTrace, "", "btnSubmit_click"); LiteralControl err = new LiteralControl(); err.Text = "<p class=\"error-message\">An error has occurred. Please contact the membership department at <a href=\"mailto:[email protected]\">[email protected]</a></p>"; lblErrorMessage.Controls.Add(err); lblErrorMessage.Visible = true; } }