Пример #1
0
        public BlogServiceResponse SubmitEmailForm(EmailFormContract emailForm)
        {
            string sql = "";
            var dataAccessHelper = new DataAccessHelper();

            bool error = false;

            #region Error Checking

            bool isFirstNameValid = true,
                isLastNameValid = true,
                isStreetAddressValid = true,
                isZipValid = true,
                isEmailValid = true,
                isPrimaryPhoneValid = true,
                isWorkTypeValid = true,
                isMessageValid = true;

            if (String.IsNullOrEmpty(emailForm.FirstName))
                isFirstNameValid = false;
            if (String.IsNullOrEmpty(emailForm.LastName))
                isLastNameValid = false;
            if (String.IsNullOrEmpty(emailForm.StreetAddress))
                isStreetAddressValid = false;
            if (String.IsNullOrEmpty(emailForm.ZipCode) || !Global.IsZipCode(emailForm.ZipCode))
                isZipValid = false;
            if (String.IsNullOrEmpty(emailForm.Email) || !Global.IsEmail(emailForm.Email))
                isEmailValid = false;
            if (String.IsNullOrEmpty(emailForm.PrimaryPhone) || !Global.IsPhoneNumber(emailForm.PrimaryPhone))
                isPrimaryPhoneValid = false;
            if (String.IsNullOrEmpty(emailForm.TypeOfWork))
                isWorkTypeValid = false;
            if (String.IsNullOrEmpty(emailForm.Message))
                isMessageValid = false;

            error =
                !(isFirstNameValid && isLastNameValid && isStreetAddressValid && isZipValid && isEmailValid &&
                  isPrimaryPhoneValid && isWorkTypeValid && isMessageValid);

            #endregion

            if (!error)
            {
                string contractorMsg = "";
                contractorMsg += "<span style=\"font-family:Arial; font-size:12px;\"><strong>Name: </strong>" +
                                 emailForm.FirstName + " " + emailForm.LastName + "<br/><strong>Address: </strong>" +
                                 emailForm.StreetAddress + "<br/><strong>City: </strong>" + emailForm.City +
                                 "<br/><strong>Zip Code: </strong>" + emailForm.ZipCode +
                                 "<br/><strong>Email: </strong>" + emailForm.Email + "<br>";
                contractorMsg += "<strong>Phone: </strong>" + emailForm.PrimaryPhone + "<br/><strong>Phone 2: </strong>" +
                                 emailForm.AlternatePhone + "<br/><strong>Work Type: </strong>" + emailForm.TypeOfWork +
                                 "<br/><strong>Message: </strong>" + emailForm.Message;
                contractorMsg += "</span>";
                //string adminMsg = "<font face='Arial' size='2'>Someone showed interest in <strong>" + ContractorName.Value + "</strong><br/><br/>" + contractorMsg + "</font>";

                string subjectMsg = "";

                //Parse comma separated list of emails - check if we are sending to multiples first
                if (emailForm.ContractorEmails != null && !BWSession.emailStartedAndSent)
                {
                    BWSession.emailStartedAndSent = true;

                    string localconid = "";

                    try
                    {
                        foreach (string strid in emailForm.ContractorEmails)
                        {
                            subjectMsg = "Best Pick Reports Website Lead";

                            //Lookup emails from contractorcategoryareaid
                            InfoLevel conInfoLevel = InfoLevel.Area;
                            bool isPrimary = false;
                            // if contractorCategoryId is Primary
                            DataRow conRow = dataAccessHelper.FindInfoRecord(InfoType.ContractorCategoryArea, int.Parse(strid), ref conInfoLevel, ref isPrimary);
                            if (conRow != null)
                            {
                                //Lookup contractor id
                                sql =
                                    "SELECT ContractorID FROM ContractorCategoryInfo WHERE ContractorCategoryID = @CCID";
                                object o = dataAccessHelper.Data.ExecuteScalar(sql,
                                    new SqlParameter("@CCID", conRow["contractorcategoryid"].ToString()));
                                if (o != null)
                                    localconid = o.ToString();

                                string[] emails = conRow["email"].ToString().Trim().Split(',');
                                foreach (string stremail in emails)
                                {
                                    if (Global.IsEmail(stremail.Trim()))
                                    {
                                        try
                                        {
                                            // Send email to contractor
                                            //!!!!HARD CODED FOR TLC DECKS
                                            if (localconid == "215")
                                                subjectMsg = "Home Reports – Dispatch 6106";

                                            Global.SendEmailNotification(stremail.Trim(), subjectMsg,
                                                ConfigurationManager.AppSettings["EmailNotification"], contractorMsg,
                                                true);
                                        }
                                        catch (Exception)
                                        {
                                            // TODO: log error in database that email couldn't be sent???
                                        }
                                    }
                                }

                                // commit contractorMsg to database
                                string insertsql =
                                    "INSERT INTO EmailData (DateSent, AreaID, CityID, CategoryID, ContractorID, FirstName, LastName, Address, City, Zip, Email, Phone, Phone2, WorkType, Message, IsPPC) " +
                                    "VALUES (@DATESENT, @AREAID, @CITYID, @CATEGORYID, @CONTRACTORID, @FIRSTNAME, @LASTNAME, @ADDRESS, @CITY, @ZIP, @EMAIL, @PHONE, @PHONE2, @WORKTYPE, @MESSAGE, @PPC)";
                                dataAccessHelper.Data.ExecuteNonQuery(insertsql,
                                    new SqlParameter("@DATESENT", DateTime.Now),
                                    new SqlParameter("@AREAID", emailForm.AreaId), //TODO get rest of the values
                                    new SqlParameter("@CITYID", emailForm.CityId),
                                    new SqlParameter("@CATEGORYID", emailForm.CategoryId),
                                    new SqlParameter("@CONTRACTORID", int.Parse(localconid)),
                                    new SqlParameter("@FIRSTNAME", emailForm.FirstName),
                                    new SqlParameter("@LASTNAME", emailForm.LastName),
                                    new SqlParameter("@ADDRESS", emailForm.StreetAddress),
                                    new SqlParameter("@CITY", emailForm.City),
                                    new SqlParameter("@ZIP", emailForm.ZipCode.Trim()),
                                    new SqlParameter("@EMAIL", emailForm.Email),
                                    new SqlParameter("@PHONE", emailForm.PrimaryPhone),
                                    new SqlParameter("@PHONE2", emailForm.AlternatePhone),
                                    new SqlParameter("@WORKTYPE", emailForm.TypeOfWork),
                                    new SqlParameter("@PPC", emailForm.IsPpc),
                                    new SqlParameter("@MESSAGE", emailForm.Message.Trim()));
                            }
                        }
                    }
                    catch (Exception)
                    {

                    }
                    finally
                    {
                        BWSession.emailStartedAndSent = false;
                    }
                }
                /*
                //Don't need to use separated fields for single and multiple contractors
                else if (ContractorEmail.Value.Trim() != "" && !BWSession.emailStartedAndSent)
                {
                    string[] emails = ContractorEmail.Value.Trim().Split(',');
                    foreach (string stremail in emails)
                    {
                        subjectMsg = "Best Pick Reports Website Lead";

                        if (Global.IsEmail(stremail.Trim()))
                        {
                            try
                            {
                                // Send email to contractor
                                //!!!!HARD CODED FOR TLC DECKS
                                if (EmailContractorID.Value == "215")
                                    subjectMsg = "Home Reports – Dispatch 6106";

                                Global.SendEmailNotification(stremail.Trim(), subjectMsg, ConfigurationManager.AppSettings["EmailNotification"], contractorMsg, true);
                                BWSession.emailStartedAndSent = true;
                            }
                            catch (Exception)
                            {
                                // TODO: log error in database that email couldn't be sent???
                            }
                        }
                    }

                    // commit contractorMsg to database
                    string insertsql = "INSERT INTO EmailData (DateSent, AreaID, CityID, CategoryID, ContractorID, FirstName, LastName, Address, City, Zip, Email, Phone, Phone2, WorkType, Message, IsPPC) " +
                        "VALUES (@DATESENT, @AREAID, @CITYID, @CATEGORYID, @CONTRACTORID, @FIRSTNAME, @LASTNAME, @ADDRESS, @CITY, @ZIP, @EMAIL, @PHONE, @PHONE2, @WORKTYPE, @MESSAGE, @PPC)";
                    basePage.Data.ExecuteNonQuery(insertsql,
                        new SqlParameter("@DATESENT", DateTime.Now),
                        new SqlParameter("@AREAID", areaID),
                        new SqlParameter("@CITYID", cityID),
                        new SqlParameter("@CATEGORYID", catid),
                        new SqlParameter("@CONTRACTORID", int.Parse(EmailContractorID.Value)),
                        new SqlParameter("@FIRSTNAME", name),
                        new SqlParameter("@LASTNAME", lastname),
                        new SqlParameter("@ADDRESS", addr),
                        new SqlParameter("@CITY", City.Text.Trim()),
                        new SqlParameter("@ZIP", Zip.Text.Trim()),
                        new SqlParameter("@EMAIL", email),
                        new SqlParameter("@PHONE", phone),
                        new SqlParameter("@PHONE2", phone2),
                        new SqlParameter("@WORKTYPE", worktype),
                        new SqlParameter("@PPC", isppc),
                        new SqlParameter("@MESSAGE", Message.Text.Trim()));
                }
                */

                //// Hide the email form and show the "Email Sent" div
                //ModalEmailForm.Visible = false;
                //ReqPanel.Visible = false;
                //EmailComplete.Visible = true;
                return new BlogServiceResponse(true, "Email sent.");
            }
            else
            {
                //// If this style isn't set, the modal popup won't display
                //ModalEmailForm.Style.Value = "display:block";
                //ReqPanel.Visible = true;
                //SendEmail.Show();
                return new BlogServiceResponse(false, "Email send failed.");
            }
        }
Пример #2
0
 public string DoWork(EmailFormContract emailForm)
 {
     // Add your operation implementation here
     return "Hello";
 }