Beispiel #1
0
        public ActionResult ContactRequestSend(ContactModel Model)
        {
            //TryValidateModel(Model);

            //Check if the dat posted is valid (All required's & email set in email field)
            if (!ModelState.IsValid)
            {
                //Not valid - so lets return the user back to the view with the data they entered still prepopulated
                return(CurrentUmbracoPage());
            }
            Node currentpage = Node.GetCurrent();

            using (CrifAustriaEFContainer objDB = new CrifAustriaEFContainer())
            {
                try
                {
                    contactUs objContact = new contactUs();
                    objContact.firstName      = Model.FirstName;
                    objContact.lastName       = Model.LastName;
                    objContact.email          = Model.Email;
                    objContact.company        = Model.Company;
                    objContact.bestWayToReach = Model.BestWayToReach;
                    objContact.message        = Model.Message;
                    objContact.industry       = ((String.IsNullOrEmpty(Model.Industry)) ? String.Empty :
                                                 ((Umbraco.TypedContent(Model.Industry) != null) ? Umbraco.TypedContent(Model.Industry).Name : Model.Industry));
                    objContact.jobTitle     = ((String.IsNullOrEmpty(Model.JobTitle)) ? String.Empty : Model.JobTitle);
                    objContact.telephone    = Model.PhoneNumber;
                    objContact.agreement    = Model.Agreement.ToString();
                    objContact.newsletter   = (Model.Newsletter) ? "Y" : "N";
                    objContact.culture      = CultureInfo.CurrentCulture.Name;
                    objContact.createdDate  = DateTime.Now;
                    objContact.modifiedDate = DateTime.Now;
                    objDB.contactUs.Add(objContact);
                    objDB.SaveChanges();

                    if (Model.Newsletter)
                    {
                        try
                        {
                            newsletterSubscription objContactNewletter = new newsletterSubscription();
                            objContactNewletter.firstName = Model.FirstName;
                            objContactNewletter.lastName  = Model.LastName;
                            objContactNewletter.email     = Model.Email;
                            objContactNewletter.company   = Model.Company;
                            objContactNewletter.jobTitle  = ((String.IsNullOrEmpty(Model.JobTitle)) ? String.Empty : Model.JobTitle);
                            objContactNewletter.industry  = ((String.IsNullOrEmpty(Model.Industry)) ? String.Empty :
                                                             ((Umbraco.TypedContent(Model.Industry) != null) ? Umbraco.TypedContent(Model.Industry).Name : Model.Industry));
                            objContact.bestWayToReach        = ((String.IsNullOrEmpty(Model.BestWayToReach)) ? String.Empty : Model.BestWayToReach);
                            objContactNewletter.agreement    = Model.Agreement.ToString();
                            objContactNewletter.culture      = CultureInfo.CurrentCulture.Name;
                            objContactNewletter.createdDate  = DateTime.Now;
                            objContactNewletter.modifiedDate = DateTime.Now;
                            objDB.newsletterSubscriptions.Add(objContactNewletter);
                            objDB.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            StringBuilder sb = new StringBuilder();

                            foreach (var failure in ex.EntityValidationErrors)
                            {
                                sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                                foreach (var error in failure.ValidationErrors)
                                {
                                    sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                                    sb.AppendLine();
                                }
                            }

                            throw new DbEntityValidationException(
                                      "Entity Validation Failed - errors follow:\n" +
                                      sb.ToString(), ex
                                      ); // Add the original exception as the innerException
                        }
                    }
                    string toEmailAddress = ""
                    , bccvalue            = ""
                    , emailSubject        = ""
                    , emailbody           = ""
                    , replyMesssage       = ""
                    , replyemailSubject   = "";
                    //string message = null;
                    if (currentpage.GetProperty("sendNotificationTo") != null && !string.IsNullOrEmpty(currentpage.GetProperty("sendNotificationTo").Value))
                    {
                        toEmailAddress = currentpage.GetProperty("sendNotificationTo").Value;
                    }
                    if (currentpage.GetProperty("bCCRecipients") != null && !string.IsNullOrEmpty(currentpage.GetProperty("bCCRecipients").Value))
                    {
                        bccvalue = currentpage.GetProperty("bCCRecipients").Value.Trim();
                    }

                    if (currentpage.GetProperty("eMailSubject") != null && !string.IsNullOrEmpty(currentpage.GetProperty("eMailSubject").Value))
                    {
                        emailSubject = currentpage.GetProperty("eMailSubject").Value;
                        emailSubject = ReplacePlaceholders(emailSubject, Model);
                    }
                    else
                    {
                        emailSubject = "New email product  request - " + DateTime.Now.Date.ToString("dd MMM yyyy");
                    }

                    if (currentpage.GetProperty("notificationBody") != null && !string.IsNullOrEmpty(currentpage.GetProperty("notificationBody").Value))
                    {
                        emailbody = currentpage.GetProperty("notificationBody").Value.Trim();
                    }
                    else
                    {
                        emailbody = @"<p>Hi,</p>
                            <p>There is a new email from the crif Austria Contact Us page.</p>
                            <p>Please see the details below.</p>
                                <p>First Name : [FIRSTNAME]</p>
                                <p>Last Name :  [LASTNAME]</p>
                                <p>Email : [EMAIL]</p>
                                <p>Telephone:[TELEPHONE]</p>
                                <p>Industry :[INDUSTRY]</p>
                                <p>Company : [COMPANY]</p>
                                <p>Job Title : [JOBTITLE]</p>
                                <p>Best Way To Reach : [BESTWAYTOREACH]</p>
                                <p>Message : [MESSAGE]</p>
                                <p>Date :[DATE]</p>
                                <p> </p>
                                <p> </p>";
                    }
                    emailbody = ReplacePlaceholders(emailbody, Model);
                    if (currentpage.GetProperty("fromEmail") != null && !string.IsNullOrEmpty(currentpage.GetProperty("fromEmail").Value))
                    {
                        var fromEmail = currentpage.GetProperty("fromEmail").Value;
                        Email.sendEmail(fromEmail, toEmailAddress, emailSubject, emailbody, "", true, "", bccvalue);
                    }

                    if (currentpage.GetProperty("replyToUser") != null && !string.IsNullOrEmpty(currentpage.GetProperty("replyToUser").Value) && currentpage.GetProperty("replyToUser").Value == "1")
                    {
                        if (currentpage.GetProperty("replyEmailSubject") != null && !string.IsNullOrEmpty(currentpage.GetProperty("replyEmailSubject").Value))
                        {
                            replyemailSubject = currentpage.GetProperty("replyEmailSubject").Value;
                            replyemailSubject = ReplacePlaceholders(replyemailSubject, Model);
                        }
                        else
                        {
                            replyemailSubject = "Thank you for contacting us.";
                        }

                        //Reply Senders Body
                        if (currentpage.GetProperty("bodyContent") != null && !string.IsNullOrEmpty(currentpage.GetProperty("bodyContent").Value))
                        {
                            replyMesssage = currentpage.GetProperty("bodyContent").Value.Trim();
                            replyMesssage = ReplacePlaceholders(replyMesssage, Model);
                        }
                        if (!string.IsNullOrEmpty(Model.Email))
                        {
                            var fromEmail = currentpage.GetProperty("fromEmail").Value;
                            Email.sendEmail(fromEmail, Model.Email, replyemailSubject, replyMesssage, "", true, "", "");
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }

                    throw new DbEntityValidationException(
                              "Entity Validation Failed - errors follow:\n" +
                              sb.ToString(), ex
                              ); // Add the original exception as the innerException
                }
            }

            var redirectthankyouPage = (currentpage.GetDescendantNodesByType("thankYou").Count() > 0 ? currentpage.GetDescendantNodesByType("thankYou").FirstOrDefault().Url : currentpage.GetAncestorByPathLevel(1).Url);

            return(Redirect(redirectthankyouPage));
        }
        public ActionResult SuccessRequestSend(SuccessRequestModel ProductRequest)
        {
            //TryValidateModel(Model);

            //Check if the dat posted is valid (All required's & email set in email field)
            if (!ModelState.IsValid)
            {
                //Not valid - so lets return the user back to the view with the data they entered still prepopulated
                return(CurrentUmbracoPage());
            }

            Node SuccessHome = currentpage.GetAncestorByPathLevel(2);

            using (CrifAustriaEFContainer objDB = new CrifAustriaEFContainer())
            {
                try
                {
                    SuccessStoryRequest objContact = new SuccessStoryRequest();
                    objContact.First_Name = ProductRequest.FirstName;
                    objContact.Last_Name  = ProductRequest.LastName;
                    objContact.Email      = ProductRequest.Email;
                    objContact.Company    = ProductRequest.Company;
                    objContact.Industry   = ((String.IsNullOrEmpty(ProductRequest.Industry)) ? String.Empty :
                                             ((Umbraco.TypedContent(ProductRequest.Industry) != null) ? Umbraco.TypedContent(ProductRequest.Industry).Name : ProductRequest.Industry));
                    objContact.JobTitle     = ((String.IsNullOrEmpty(ProductRequest.JobTitle)) ? String.Empty : ProductRequest.JobTitle);
                    objContact.Telephone    = ((String.IsNullOrEmpty(ProductRequest.PhoneNumber)) ? String.Empty : ProductRequest.PhoneNumber);
                    objContact.Agreement    = ProductRequest.Agreement.ToString();
                    objContact.Newsletter   = (ProductRequest.Newsletter) ? "Y" : "N";
                    objContact.Culture      = CultureInfo.CurrentCulture.Name;
                    objContact.Culture      = CultureInfo.CurrentCulture.Name;
                    objContact.ProductName  = currentpage.Name;
                    objContact.CreatedDate  = DateTime.Now;
                    objContact.ModifiedDate = DateTime.Now;
                    objDB.SuccessStoryRequests.Add(objContact);
                    objDB.SaveChanges();

                    if (ProductRequest.Newsletter)
                    {
                        //Dictionary<string, string> dictFormValuesNewsletter = new Dictionary<string, string>();
                        //dictFormValuesNewsletter.Add("First Name", Model.FirstName);
                        //dictFormValuesNewsletter.Add("Last Name", Model.LastName);
                        //dictFormValuesNewsletter.Add("Email", Model.Email);
                        //dictFormValuesNewsletter.Add("Job Title", Model.JobTitle);
                        //dictFormValuesNewsletter.Add("Telephone Number", "");
                        //dictFormValuesNewsletter.Add("company", Model.Company);
                        //dictFormValuesNewsletter.Add("Industry", (String.IsNullOrEmpty(Model.Industry)) ? String.Empty : Model.Industry);
                        //dictFormValuesNewsletter.Add("Country", list.ConvertTwoLetterNameFullName(Model.Country));
                        //dictFormValuesNewsletter.Add("linkedinbio", ((!String.IsNullOrEmpty(Model.linkedinProfileUrl)) ? Model.linkedinProfileUrl : String.Empty));

                        //strFormGUID = System.Configuration.ConfigurationManager.AppSettings["hubspotnewsletterformId"].ToString();

                        //bool blnRetNewsletter = Post_To_HubSpot_SubmitFormsAPI(intPortalID, strFormGUID, dictFormValuesNewsletter, strHubSpotUTK, strIpAddress, strPageTitle, strPageURL, ref strError);
                        //if (blnRetNewsletter)
                        //{
                        //    try
                        //    {
                        //        ccf_NewsLetter objContactNewletter = new ccf_NewsLetter();
                        //        objContactNewletter.First_Name = Model.FirstName;
                        //        objContactNewletter.Last_Name = Model.LastName;
                        //        objContactNewletter.Email = Model.Email;
                        //        objContactNewletter.Telephone = "";
                        //        objContactNewletter.Company = Model.Company;
                        //        objContactNewletter.JobTitle = Model.JobTitle;
                        //        objContactNewletter.Industry = ((String.IsNullOrEmpty(Model.Industry)) ? String.Empty : Model.Industry);
                        //        objContactNewletter.Country = list.ConvertTwoLetterNameFullName(Model.Country);
                        //        objContactNewletter.Agreement = Model.Agreement.ToString();
                        //        objContactNewletter.Culture = CultureInfo.CurrentCulture.Name;
                        //        objContactNewletter.CreatedDate = DateTime.Now;
                        //        objContactNewletter.ModifiedDate = DateTime.Now;
                        //        objDB.ccf_NewsLetter.Add(objContactNewletter);
                        //        objDB.SaveChanges();
                        //    }
                        //    catch (DbEntityValidationException ex)
                        //    {
                        //        StringBuilder sb = new StringBuilder();

                        //        foreach (var failure in ex.EntityValidationErrors)
                        //        {
                        //            sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        //            foreach (var error in failure.ValidationErrors)
                        //            {
                        //                sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                        //                sb.AppendLine();
                        //            }
                        //        }

                        //        throw new DbEntityValidationException(
                        //            "Entity Validation Failed - errors follow:\n" +
                        //            sb.ToString(), ex
                        //        ); // Add the original exception as the innerException
                        //    }
                        //}
                        //else
                        //{
                        //    return CurrentUmbracoPage();
                        //}
                    }
                    string toEmailAddress = ""
                    , bccvalue            = ""
                    , emailSubject        = ""
                    , emailbody           = ""
                    , replyMesssage       = ""
                    , replyemailSubject   = "";
                    //string message = null;
                    if (SuccessHome.GetProperty("sendNotificationTo") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("sendNotificationTo").Value))
                    {
                        toEmailAddress = SuccessHome.GetProperty("sendNotificationTo").Value;
                    }
                    if (SuccessHome.GetProperty("bCCRecipients") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("bCCRecipients").Value))
                    {
                        bccvalue = SuccessHome.GetProperty("bCCRecipients").Value.Trim();
                    }

                    if (SuccessHome.GetProperty("eMailSubject") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("eMailSubject").Value))
                    {
                        emailSubject = SuccessHome.GetProperty("eMailSubject").Value;
                        emailSubject = ReplacePlaceholders(emailSubject, ProductRequest);
                    }
                    else
                    {
                        emailSubject = "New email product  request - " + DateTime.Now.Date.ToString("dd MMM yyyy");
                    }

                    if (SuccessHome.GetProperty("notificationBody") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("notificationBody").Value))
                    {
                        emailbody = SuccessHome.GetProperty("notificationBody").Value;
                    }
                    else
                    {
                        emailbody = @"<p>Hi,</p>
                            <p>There is a new email from the crif Austria Success Stories request page.</p>
                            <p>Please see the details below.</p>
                                <p>First Name : [FIRSTNAME]</p>
                                <p>Last Name :  [LASTNAME]</p>
                                <p>Email : [EMAIL]</p>
                                <p>Telephone:[TELEPHONE]</p>
                                <p>Industry :[INDUSTRY]</p>
                                <p>Company : [COMPANY]</p>
                                <p>Job Title : [JOBTITLE]</p>
                                <p>Product : [PRODUCT]</p>
                                <p>Date :[DATE]</p>
                                <p> </p>
                                <p> </p>";
                    }
                    emailbody = ReplacePlaceholders(emailbody, ProductRequest);
                    if (SuccessHome.GetProperty("fromEmail") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("fromEmail").Value))
                    {
                        var fromEmail = SuccessHome.GetProperty("fromEmail").Value;
                        Email.sendEmail(fromEmail, toEmailAddress, emailSubject, emailbody, "", true, "", bccvalue);
                    }

                    if (SuccessHome.GetProperty("replyToUser") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("replyToUser").Value) && SuccessHome.GetProperty("replyToUser").Value == "1")
                    {
                        if (SuccessHome.GetProperty("replyEmailSubject") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("replyEmailSubject").Value))
                        {
                            replyemailSubject = SuccessHome.GetProperty("replyEmailSubject").Value;
                            replyemailSubject = ReplacePlaceholders(replyemailSubject, ProductRequest);
                        }
                        else
                        {
                            replyemailSubject = "Thank you for contacting us.";
                        }

                        //Reply Senders Body
                        if (SuccessHome.GetProperty("bodyContent") != null && !string.IsNullOrEmpty(SuccessHome.GetProperty("bodyContent").Value))
                        {
                            replyMesssage = SuccessHome.GetProperty("bodyContent").Value.Trim();
                            replyMesssage = ReplacePlaceholders(replyMesssage, ProductRequest);
                        }
                        if (!string.IsNullOrEmpty(ProductRequest.Email))
                        {
                            var fromEmail = SuccessHome.GetProperty("fromEmail").Value;
                            Email.sendEmail(fromEmail, ProductRequest.Email, replyemailSubject, replyMesssage, "", true, "", "");
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }

                    throw new DbEntityValidationException(
                              "Entity Validation Failed - errors follow:\n" +
                              sb.ToString(), ex
                              ); // Add the original exception as the innerException
                }
            }

            return(Redirect(currentpage.GetAncestorByPathLevel(1).GetDescendantNodesByType("thankYou").Where(x => x.Level == 2).First().Url + "?id=" + @currentpage.Id));
        }