Exemplo n.º 1
0
        public void Run()
        {
            try
            {
                List <HarperLINQ.Referral> referrals = Referral.GetNeedsReminderList();
                foreach (Referral referral in referrals)
                {
                    tbl_Customer member = new tbl_Customer(referral.memberid, false);
                    string       cc     = null;
                    if (referral.ccmember)
                    {
                        cc = member.cusEmail;
                    }

                    ReferralOffer offer      = new ReferralOffer(referral.keycode, referral.pubcode);
                    string        membername = string.Format("{0} {1}", member.cusFirstName, member.cusLastName);
                    string        link       = string.Format("{0}/Referral/Redeem.aspx?ReferralId={1}", ConfigurationManager.AppSettings["server"], System.Web.HttpUtility.UrlEncode(HarperCRYPTO.Cryptography.EncryptData(referral.id.ToString())));
                    string        emailbody  = offer.reminderemailcopy.Replace("[membername]", membername).Replace("[friendname]", referral.friendname).Replace("[link]", link);

                    SimpleMail reminder = new SimpleMail(offer.reminderemailsubject,
                                                         offer.reminderemailfromaddress,
                                                         referral.friendemail,
                                                                       //"*****@*****.**",
                                                         string.Empty, //do not cc the reminders?
                                                         offer.reminderemailbcc,
                                                         emailbody,
                                                         offer.reminderemailishtml.HasValue ? offer.reminderemailishtml.Value : true,
                                                         offer.reminderemailsmtp);
                    reminder.Save();
                    referral.reminderemailid = reminder.id;
                    referral.Save();
                }
            }
            catch (Exception ex)
            {
                string SourceName = "ReferralReminder";
                if (!EventLog.SourceExists(SourceName))
                {
                    EventLog.CreateEventSource(SourceName, "Application");
                }

                EventLog eventLog = new EventLog();
                eventLog.Source = SourceName;
                string message = string.Format("Exception: {0} \n\nStack: {1}", ex.Message, ex.StackTrace);
                eventLog.WriteEntry(message, EventLogEntryType.Error);
            }
        }
Exemplo n.º 2
0
    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;
        }
    }
Exemplo n.º 3
0
        public BaseResponse CreateReferral(string cusid, string membername, string memberemail, string keycode,
                                           string pubcode, string friendname, string friendemailaddress, bool ccmember)
        {
            methodName = "CreateReferral";

            List <Message> errors   = new List <Message>();
            Referral       referral = new Referral();

            try
            {
                tbl_Customer member = new tbl_Customer(int.Parse(cusid), false);

                #region validate input
                if (member == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.memberDoesNotExistError, cusid, "", null));
                }
                if (member.SfgId == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.invalidMemberIdError, "", "", null));
                }
                if (string.IsNullOrEmpty(membername))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberNameError, "", "", null));
                }
                if (ccmember && string.IsNullOrEmpty(memberemail))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberEmailError, "", "", null));
                }
                if (string.IsNullOrEmpty(keycode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingKeycodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(pubcode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingPubcodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendname))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendNameError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendemailaddress))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendEmailError, "", "", null));
                }
                #endregion

                #region enforce business rules
                tbl_Customer friend = new tbl_Customer(friendemailaddress, false);
                try
                {
                    Referral existing_referral = new Referral(friendemailaddress);

                    if (memberemail == friendemailaddress)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.cannotReferSelfError, "", "", null));
                    }
                    else if (friend.cusID > 0)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingMemberError, "", "", null));
                    }
                    else if (existing_referral.dateredeemed == null)
                    {
                        if (existing_referral.id > 0 && existing_referral.dateexpires.CompareTo(DateTime.Now) >= 0)
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingReferralError, "", "", null));
                        }
                    }
                    if (errors.Count <= 0)
                    {
                        GetMemberResponse checkFriend = (GetMemberByUserName(friendemailaddress).TypedResponse as GetMemberResponse);
                        if (checkFriend != null && (checkFriend.MemberFound || checkFriend.WebAccountFound))
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseSFGError, "", "", null));
                        }
                    }
                }
                catch (HarperLINQ.DataLoadException dle)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseAHError, "", "", null));
                }
                if (errors.Count() > 0)
                {
                    string errstring = string.Empty;
                    foreach (Message msg in errors)
                    {
                        string sfgmessages = string.Empty;
                        if (msg.SfgMessages != null)
                        {
                            foreach (string sfgmsg in msg.SfgMessages)
                            {
                                sfgmessages += string.Format("SFGMessage: {0}", sfgmsg);
                            }
                        }
                        errstring += string.Format("AhMessage: {0}|| {1}", new object[] { msg.AhMessage, sfgmessages });
                    }
                    throw new Exception(string.Format("Error creating referral: [{0}]", errstring));
                }
                #endregion

                ReferralOffer offer = new ReferralOffer(keycode, pubcode);


                #region save referral
                referral = new Referral(int.Parse(cusid), membername, memberemail, keycode, pubcode, friendname, friendemailaddress, ccmember, offer.triallengthinmonths, offer.offerexpiresmonths);
                referral.Save();
                #endregion

                #region send email
                //create mailer and sent mail
                Mailer mailer = new Mailer();

                string ccEmail = memberemail;

                if (!ccmember)
                {
                    ccEmail = string.Empty;
                }

                mailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                 ConfigurationManager.AppSettings["mailservicepwd"],
                                 string.Format("Membership Invitation from {0}", membername),
                                 ConfigurationManager.AppSettings["referemailfrom"],
                                 friendemailaddress,
                                 ccEmail,
                                 string.Empty,
                                 referral.GetReferralEmailBody(),
                                 true,
                                 ConfigurationManager.AppSettings["smtpserver"]);
                #endregion
            }
            catch (Exception ex)
            {
                LogMethodError(methodName, ex);
            }
            if (baseResponse != null && baseResponse.Messages != null)
            {
                foreach (Message error in errors)
                {
                    baseResponse.Messages.Add(error);
                }
            }
            if (baseResponse.Messages.Count() <= 0 && referral != null && referral.id >= 0)
            {
                #region create typed response
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = true;
                (baseResponse.TypedResponse as ReferralResponse).referralid = referral.id;
                #endregion
            }
            else
            {
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = false;
            }

            return(baseResponse);
        }