Beispiel #1
0
        public static void LogError(string method, string message, bool sendemail)
        {
            try
            {
                //EventLog.WriteEntry(eventSource, string.Format("Error in: {0}\r\nMessage:{1}", new object[] { method, message }), EventLogEntryType.Error);
                
                AppEventLog appLog = new AppEventLog();
                appLog.AppName = "HarperSERVICE";
                appLog.DateCreated = DateTime.Now;
                appLog.Event = "ERROR_LOGGED";
                appLog.Message1 = message;
                appLog.Section = method;
                using (SupportDataDataContext context = new SupportDataDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    context.AppEventLogs.InsertOnSubmit(appLog);
                    context.SubmitChanges();
                }

                Mailer emailer = new Mailer();
                emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                    ConfigurationManager.AppSettings["mailservicepwd"],
                    "SERVICE ERROR LOGGED",
                    ConfigurationManager.AppSettings["erroremailsfrom"],
                    ConfigurationManager.AppSettings["erroremailsto"],
                    string.Empty, string.Empty,
                    message,
                    false, ConfigurationManager.AppSettings["erroremailsmtpserver"]);                
            }
            catch { }
        }
        private void SendNewMemberEmail(string salutation, string firstname, string lastname, string suffix, string sfgid, string email)
        {
            string EmailBody = System.IO.File.ReadAllText(ConfigurationManager.AppSettings["newuseremailtemplate"]);
            string ThankYou  = ", ";

            ThankYou += string.IsNullOrEmpty(salutation) ? "" : salutation + " ";
            ThankYou += string.IsNullOrEmpty(firstname) ? "" : firstname + " ";
            ThankYou += string.IsNullOrEmpty(lastname) ? "" : lastname + " ";
            ThankYou += string.IsNullOrEmpty(suffix) ? "" : suffix;
            if (ThankYou.Length > 0 && ThankYou.LastIndexOf(", ") == ThankYou.Length - 2)
            {
                ThankYou = ThankYou.Substring(0, ThankYou.LastIndexOf(", "));
            }
            if (ThankYou.Length > 0 && ThankYou.LastIndexOf(" ") == ThankYou.Length - 1)
            {
                ThankYou = ThankYou.Substring(0, ThankYou.LastIndexOf(" "));
            }
            EmailBody = EmailBody.Replace("[[sfgid]]", sfgid);
            EmailBody = EmailBody.Replace("[[thankyou]]", ThankYou);
            EmailBody = EmailBody.Replace("[[baseurl]]", ConfigurationManager.AppSettings["baseurl"]);
            string EmailSubject = ConfigurationManager.AppSettings["newuseremailsubject"];
            string EmailFrom    = ConfigurationManager.AppSettings["newuseremailfrom"];

            SupportClasses.Mailer Emailer = new SupportClasses.Mailer();
            Emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                              ConfigurationManager.AppSettings["mailservicepwd"],
                              EmailSubject, EmailFrom, email,
                              string.Empty, string.Empty,
                              EmailBody, true,
                              ConfigurationManager.AppSettings["EmailServer"]);
        }
 public bool SendMail(string hashedusername, string hashedpassword, string subject, string fromaddress, string toaddress, string cc, string bcc, string body, bool ishtml, string smtp)
 {
     //TODO: add calling server authentication
     string user = Cryptography.DeHash(hashedusername);
     string pwd = Cryptography.DeHash(hashedpassword);
     Mailer emailer = new Mailer();
     return emailer.SendEmail(user, pwd, subject, fromaddress, toaddress, cc, bcc, body, ishtml, smtp);
 }
        public BaseResponse RedeemReferralSubscription(int referralid, string firstname, string lastname,
            string emailaddress, string countrycode, string address1, string address2,
            string city, string region, string postal, bool optin, string username, string password)
        {
            List<Message> errors = new List<Message>();
            string errortext = string.Empty;
            try
            {
                HarperLINQ.Referral referral;

                #region input validation
                using (AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    referral = context.Referrals.SingleOrDefault(r => r.id == referralid);
                }
                if (referral == null)
                {
                    errortext = string.Format(BusinessLogicStrings.invalidReferralIdError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                else if (referral.dateredeemed != null || referral.friendid > 0)
                {
                    errortext = string.Format(BusinessLogicStrings.RedeemedReferralError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                else if (referral.dateexpires <= DateTime.Now)
                {
                    errortext = string.Format(BusinessLogicStrings.expiredReferralError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                #endregion
                
                else
                {
                    #region sub order insert
                    Member giftData = new Member();
                    giftData.FirstName = firstname;
                    giftData.LastName = lastname;
                    giftData.OptIn = optin;
                    giftData.Email = emailaddress;

                    giftData.Address = new Address();
                    giftData.Address.Address1 = address1;
                    giftData.Address.Address2 = address2;
                    giftData.Address.City = city;
                    giftData.Address.State = region;
                    giftData.Address.PostalCode = postal;
                    giftData.Address.Country = countrycode;

                    SubscriptionServiceRequest request = new SubscriptionServiceRequest(referral, giftData);
                    baseResponse = SubOrderInsert.RedeemReferralSubscription(request);
                    foreach (Message err in baseResponse.Messages)
                    {
                        errors.Add(err);
                    }
                    #endregion

                    MembershipLogic memberlogic = new MembershipLogic();
                    BaseResponse memberResponse = null;
                    if (errors.Count <= 0)
                    {
                        memberResponse = memberlogic.GetMemberByUserName(emailaddress);
                    }

                    if (!(errors.Count > 0 
                        || memberResponse == null
                        || memberResponse.TypedResponse == null
                        || memberResponse.TypedResponse.Success == false))
                    {
                        using (AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                        {
                            GetMemberResponse getMemberResponse = memberResponse.TypedResponse as GetMemberResponse;
                            if (getMemberResponse.MemberFound && getMemberResponse.MemberData != null)
                            {
                                string newMemberId = getMemberResponse.MemberData.MemberId;

                                #region create the user at AH
                                object[] create_response = tbl_Customer.CreateCustomer(address1, address2, "", city, region, 
                                    countrycode, postal, "Z1", password, "PERSONAL", "", 
                                    firstname, "", lastname, "", emailaddress, username, newMemberId, referral.pubcode, DateTime.Now.AddMonths(referral.subscriptionlength).ToShortDateString(), DateTime.Now.ToShortDateString(), username, "");
                                tbl_Customer customer = (tbl_Customer)create_response[1];
                                #endregion

                                #region referral data at AH
                                referral = context.Referrals.SingleOrDefault(r => r.id == referralid);
                                referral.dateredeemed = DateTime.Now;
                                referral.friendid = customer.cusID;
                                context.SubmitChanges();
                                #endregion

                                #region send email
                                Mailer mailer = new Mailer();

                                mailer.SendEmail(
                                    ConfigurationManager.AppSettings["mailserviceuser"], 
                                    ConfigurationManager.AppSettings["mailservicepwd"],
                                    "Welcome to the Andrew Harper Community!", 
                                    ConfigurationManager.AppSettings["referemailfrom"],
                                    referral.friendemail,
                                    string.Empty, 
                                    string.Empty,
                                    referral.GetReferralUserCreatedEmailBody(), 
                                    true, 
                                    ConfigurationManager.AppSettings["smtpserver"]);
                                #endregion
                            }
                        }
                    }
                    else
                    {
                        errortext = string.Format(BusinessLogicStrings.RetrieveMemeberError, new object[] { referralid, emailaddress });
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                    }
                }

                baseResponse.TypedResponse = new AHResponse();
                if (errors.Count == 0)
                {
                    baseResponse.TypedResponse.Success = true;
                }
                else
                {
                    baseResponse.TypedResponse.Success = false;
                }
            }
            
            catch (Exception ex)
            {
                baseResponse.TypedResponse.Success = false;
                errortext = string.Format(BusinessLogicStrings.UnknownReferralError, ex.Message);
                errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
            }
            foreach (Message error in errors)
            {
                if (baseResponse == null)
                {
                    baseResponse = new BaseResponse();
                }
                baseResponse.Messages.Add(error);

                StringBuilder error_text = new StringBuilder();
                error_text.AppendLine("REFERRAL ERROR LOGGED");
                error_text.AppendLine(string.Format("REFERRALID {0}", referralid));
                baseResponse.Messages.Add(error);
                error_text.AppendLine(string.Format("ERROR: ", new object[] { }));
                EventLogger.LogError("SubscriptionLogic.RedeemReferralSubscription", error_text.ToString(), true);
            }
            return baseResponse;
        }        
        private void SendNewMemberEmail(string salutation, string firstname, string lastname, string suffix, string sfgid, string email)
        {
            string EmailBody = System.IO.File.ReadAllText(ConfigurationManager.AppSettings["newuseremailtemplate"]);
            string ThankYou = ", ";
            ThankYou += string.IsNullOrEmpty(salutation) ? "" : salutation + " ";
            ThankYou += string.IsNullOrEmpty(firstname) ? "" : firstname + " ";
            ThankYou += string.IsNullOrEmpty(lastname) ? "" : lastname + " ";
            ThankYou += string.IsNullOrEmpty(suffix) ? "" : suffix;
            if (ThankYou.Length > 0 && ThankYou.LastIndexOf(", ") == ThankYou.Length - 2)
            {
                ThankYou = ThankYou.Substring(0, ThankYou.LastIndexOf(", "));
            }
            if (ThankYou.Length > 0 && ThankYou.LastIndexOf(" ") == ThankYou.Length - 1)
            {
                ThankYou = ThankYou.Substring(0, ThankYou.LastIndexOf(" "));
            }
            EmailBody = EmailBody.Replace("[[sfgid]]", sfgid);
            EmailBody = EmailBody.Replace("[[thankyou]]", ThankYou);
            EmailBody = EmailBody.Replace("[[baseurl]]", ConfigurationManager.AppSettings["baseurl"]);
            string EmailSubject = ConfigurationManager.AppSettings["newuseremailsubject"];
            string EmailFrom = ConfigurationManager.AppSettings["newuseremailfrom"];

            SupportClasses.Mailer Emailer = new SupportClasses.Mailer();
            Emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                ConfigurationManager.AppSettings["mailservicepwd"],
                EmailSubject, EmailFrom, email,
                string.Empty, string.Empty,
                EmailBody, true,
                ConfigurationManager.AppSettings["EmailServer"]);
        }
Beispiel #6
0
    protected void SubmitClicked(object sender, EventArgs e)
    { 
        if (string.IsNullOrEmpty(email.Text))
        {
            SetError(new Exception("Email address is required."));
            pnlForm.Visible = true;
        }
        else
        {
            try
            {
                HarperSecureService.UpdatePasswordResponse updateResponse = new HarperSecureService.UpdatePasswordResponse();
                HarperLINQ.tbl_Customer user = new HarperLINQ.tbl_Customer(email.Text, false);
                if (user == null)
                {
                    SetError(new Exception("Unable to find a member with this address."));
                    lblMessage.Text = "Unable to find a member with this email address.";
                    pnlForm.Visible = true;
                }
                else
                {
                    if (string.IsNullOrEmpty(user.cusPassword))
                    {
                        SetError(new Exception("Error retrieving password - no password or blank password on file."));
                        lblMessage.Text = string.Format("{0}</br>{1}</br>", new object[] { Resources.GlobalStrings.Apology, Resources.GlobalStrings.ContactUs });
                        pnlForm.Visible = true;
                    }
                    else
                    {
                        string pwd = Cryptography.Decrypt256FromHEX(user.cusPassword);
                        if (!string.IsNullOrEmpty(user.cusUserName)
                            && !string.IsNullOrEmpty(pwd)
                            && !string.IsNullOrEmpty(email.Text))
                        {
                            SupportClasses.Mailer Emailer = new SupportClasses.Mailer();
                            Emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                ConfigurationManager.AppSettings["mailservicepwd"],
                                "Andrew Harper Password Reminder",
                                ConfigurationManager.AppSettings["MembershipEmailFrom"].ToString(),
                                user.cusEmail,
                                string.Empty, string.Empty,
                                getEmailBody(user.cusUserName, pwd), true,
                                ConfigurationManager.AppSettings["EmailServer"]);

                            lblConfirmation.Visible = true;
                            pnlForm.Visible = false;
                            lblMessage.Visible = false;
                            string s = "<p>As requested, a reminder of your username and password has been sent to " + user.cusEmail + ".  Please retrieve your credentials, and use them to log in to our website <a href=\"http://www.andrewharper.com/login\" target=\"_top\">here</a>.</p><p>As a reminder, all username and passwords are case-sensitive.</p><p>If you do not receive the email shortly, please check your spam or junk email folder.  If you continue to experience difficulties, please contact Membership at [email protected] or call (866) 831-4314 from the U.S or +1 (512) 904-7342 internationally.</p>";
                            lblConfirmation.Text = s;// string.Format("A reminder has been sent to {0}. If you do not receive the email within thirty minutes please check your spam or junk email folder.", email.Text);
                            lblConfirmation.Visible = true;

                            WriteLog(string.Format("Password for {0} was sent to {1}", new object[] { user.cusUserName, user.cusEmail }));
                        }
                        else
                        {
                            SetError(new Exception("Unable to send password reminder email."));
                            lblMessage.Text = "Unable to send password reminder email.";
                            pnlForm.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SetError(new Exception("Unable to send password reminder email, email address may be duplicate."));
                lblMessage.Text = "Unable to send password reminder email, email address may be duplicate.";
                pnlForm.Visible = true;
                WriteLog(ex);
            }
        }
    }
        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;
        }
Beispiel #8
0
    protected void SubmitClicked(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(email.Text))
        {
            SetError(new Exception("Email address is required."));
            pnlForm.Visible = true;
        }
        else
        {
            try
            {
                HarperSecureService.UpdatePasswordResponse updateResponse = new HarperSecureService.UpdatePasswordResponse();
                HarperLINQ.tbl_Customer user = new HarperLINQ.tbl_Customer(email.Text, false);
                if (user == null)
                {
                    SetError(new Exception("Unable to find a member with this address."));
                    lblMessage.Text = "Unable to find a member with this email address.";
                    pnlForm.Visible = true;
                }
                else
                {
                    if (string.IsNullOrEmpty(user.cusPassword))
                    {
                        SetError(new Exception("Error retrieving password - no password or blank password on file."));
                        lblMessage.Text = string.Format("{0}</br>{1}</br>", new object[] { Resources.GlobalStrings.Apology, Resources.GlobalStrings.ContactUs });
                        pnlForm.Visible = true;
                    }
                    else
                    {
                        string pwd = Cryptography.Decrypt256FromHEX(user.cusPassword);
                        if (!string.IsNullOrEmpty(user.cusUserName) &&
                            !string.IsNullOrEmpty(pwd) &&
                            !string.IsNullOrEmpty(email.Text))
                        {
                            SupportClasses.Mailer Emailer = new SupportClasses.Mailer();
                            Emailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                              ConfigurationManager.AppSettings["mailservicepwd"],
                                              "Andrew Harper Password Reminder",
                                              ConfigurationManager.AppSettings["MembershipEmailFrom"].ToString(),
                                              user.cusEmail,
                                              string.Empty, string.Empty,
                                              getEmailBody(user.cusUserName, pwd), true,
                                              ConfigurationManager.AppSettings["EmailServer"]);

                            lblConfirmation.Visible = true;
                            pnlForm.Visible         = false;
                            lblMessage.Visible      = false;
                            string s = "<p>As requested, a reminder of your username and password has been sent to " + user.cusEmail + ".  Please retrieve your credentials, and use them to log in to our website <a href=\"http://www.andrewharper.com/login\" target=\"_top\">here</a>.</p><p>As a reminder, all username and passwords are case-sensitive.</p><p>If you do not receive the email shortly, please check your spam or junk email folder.  If you continue to experience difficulties, please contact Membership at [email protected] or call (866) 831-4314 from the U.S or +1 (512) 904-7342 internationally.</p>";
                            lblConfirmation.Text    = s;// string.Format("A reminder has been sent to {0}. If you do not receive the email within thirty minutes please check your spam or junk email folder.", email.Text);
                            lblConfirmation.Visible = true;

                            WriteLog(string.Format("Password for {0} was sent to {1}", new object[] { user.cusUserName, user.cusEmail }));
                        }
                        else
                        {
                            SetError(new Exception("Unable to send password reminder email."));
                            lblMessage.Text = "Unable to send password reminder email.";
                            pnlForm.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SetError(new Exception("Unable to send password reminder email, email address may be duplicate."));
                lblMessage.Text = "Unable to send password reminder email, email address may be duplicate.";
                pnlForm.Visible = true;
                WriteLog(ex);
            }
        }
    }