コード例 #1
0
        public ActionResult Create(ABTest abtest)
        {
            if (ModelState.IsValid)
            {
                ABTestClient abtc = new ABTestClient();

                try
                {
                    abtc.CreateNew(abtest.RowKey);
                    return(RedirectToAction("Index"));
                }
                catch
                {
                    ModelState.AddModelError("error", "Error creating new test");
                }
            }

            return(View(abtest));
        }
コード例 #2
0
        public ActionResult Index(FormCollection collection)
        {
            if (Request.Cookies["extendedrecordcomplete"] != null)
            {
                return(RedirectToAction("Index", "SkillTest"));
            }

            #region IP ADDRESS
#if DEBUG
            string randomip = RandomHelper.Instance.Next(1, 256) + "." + RandomHelper.Instance.Next(0, 256) + "." + RandomHelper.Instance.Next(0, 256) + "." + RandomHelper.Instance.Next(1, 256);
#endif
            string ipaddress = "";
#if DEBUG
            ipaddress = randomip;
#else
            ipaddress = Request.UserHostAddress;
#endif
            #endregion

            double LEAD_CONVERSION_VALUE   = 1;
            double RECORD_CONVERSION_VALUE = 0.2;

            double conversionValue = 0;

            string schoolsearchresultid = FromCookie("schoolsearchresultid");

            string campaignid = FormValue(collection, "cbncampaign", "13564694");

            string salutation = FormValue(collection, "salutation", "").Trim().ToProperCase();
            string gender     = salutation.ToLower() == "mr" ? "M" : "F";
            string firstname  = FormValue(collection, "firstname", "GET THIS");
            string lastname   = FormValue(collection, "lastname", "GET THIS");

            string email    = FormValue(collection, "email", "GET THIS").Trim().ToLower();
            string zip      = FormValue(collection, "zip", "GET THIS");
            string phone    = FormValue(collection, "phone", "GET THIS").Replace(".", "").Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");
            string address1 = FormValue(collection, "address1", "GET THIS");
            string city     = FormValue(collection, "city", "");
            string state    = FormValue(collection, "state", "");

            string educationlevel = FormValue(collection, "education_level", "SC");
            string eduintent      = FormValue(collection, "edu_intent", "YES");
            string military       = FormValue(collection, "military", "None");
            string gradyear       = FormValue(collection, "gradyear", "GET THIS");
            string sourceform     = FormValue(collection, "sourceform", "");

            string dobyear = FormValue(collection, "dobyear", "");

            Random rnd      = new Random(DateTime.Now.Millisecond);
            int    dobmonth = rnd.Next(1, 13);
            int    dobday   = rnd.Next(1, 29);

            string schoolvariables = "";
            if (Request.Cookies["schoolvariables"] != null)
            {
                schoolvariables = HttpUtility.UrlDecode(Request.Cookies["schoolvariables"].Value);
            }

            //GA variable
            string utmsource   = FromCookie("utm_source"),
                   utmcampaign = FromCookie("utm_campaign"),
                   utmcontent  = FromCookie("utm_content"),
                   utmterm     = FromCookie("utm_term");

            //Advertise.com variables
            string advertise_affsub        = FromCookie("AFFSUB"),
                   advertise_affiliate     = FromCookie("AFFILIATE"),
                   advertise_country       = FromCookie("COUNTRY"),
                   advertise_countrycode   = FromCookie("COUNTRYCODE"),
                   advertise_geo           = FromCookie("GEO"),
                   advertise_subid         = FromCookie("SUBID"),
                   advertise_terms_html_kw = FromCookie("TERMS_HTML_KW"),
                   advertise_terms         = FromCookie("TERMS");

            string[] distinctSubmissions = schoolvariables.Split('^');
            foreach (string submission in distinctSubmissions)
            {
                if (submission != "")
                {
                    string[] submissionTokens = submission.Split('!');

                    string campuskey  = submissionTokens[3];
                    string programkey = submissionTokens.Length > 4 ? submissionTokens[4] : "";



                    String strPost = "campaign_id=" + campaignid +
                                     "&id=1727" +
                                     "&ip=" + ipaddress +
                                     "&client_id=" + submissionTokens[1] +
                                     "&salutation=" + salutation +
                                     "&gender=" + gender +
                                     "&firstname=" + firstname.Trim() +
                                     "&lastname=" + lastname.Trim() +
                                     "&email=" + email +
                                     "&zip=" + zip +
                                     "&phone=" + phone +
                                     "&address1=" + address1 +
                                     "&city=" + city +
                                     "&state=" + state +
                                     "&education_level=" + educationlevel +
                                     "&educationlevel=" + educationlevel +
                                     "&edu_intent=YES" +
                                     "&military=" + military +
                                     "&campus_key=" + submissionTokens[3] +
                                     "&program_key=" + programkey +
                                     "&gradyear=" + gradyear +
                                     "&dobyear=" + dobyear +
                                     "&dobmonth=" + dobmonth.ToString() +
                                     "&dobday=" + dobday.ToString() +
                                     "&form_id=" + submissionTokens[2] +
                                     "&program=" + submissionTokens[0];

                    int igradyear;
                    int.TryParse(gradyear, out igradyear);

                    //Do not submit young leads to CBN
                    if (igradyear <= DateTime.Now.Year)
                    {
                        //Update the record with address
                        DelayedRecordClient drc = new DelayedRecordClient();
                        //First check if delayed record already exists for this email
                        DelayedRecord dr = drc.GetByRowKey(email.FormatEmailAsProgrammaticId());
                        if (dr != null)
                        {
                            if (dr.Address1 != address1)
                            {
                                dr.Address1  = address1;
                                dr.EduIntent = "YES";
                                drc.Update(dr);
                            }
                        }
                    }

                    string submissionResult = "";

                    try
                    {
                        if (igradyear <= DateTime.Now.Year)
                        {
                            submissionResult = SubmitLead(strPost);
                            conversionValue += LEAD_CONVERSION_VALUE;
                        }

                        SkillCowRequestSubmissionClient rsc = new SkillCowRequestSubmissionClient();

                        string mode = "external";
                        if (Request.Cookies["mode"] != null)
                        {
                            mode = Request.Cookies["mode"].Value;
                        }

                        string testresults = "";
                        if (Request.Cookies["testresults"] != null)
                        {
                            testresults = DecodeCookieCharacters(Request.Cookies["testresults"].Value);
                        }

                        string recommendations = "";
                        if (Request.Cookies["recommendations"] != null)
                        {
                            recommendations = DecodeCookieCharacters(Request.Cookies["recommendations"].Value);
                        }

                        string careerChoicesJson = GetCareerChoicesJson();
                        string data = "{\"careerchoices\":" + careerChoicesJson + "}";

                        rsc.AddNewItem(new SkillCowRequestSubmission
                        {
                            Salutation       = salutation,
                            Name             = (firstname + " " + lastname).Trim(),
                            Zip              = zip,
                            Email            = email,
                            Address1         = address1,
                            Phone            = phone,
                            IP               = ipaddress,
                            Mode             = mode,
                            CampaignId       = campaignid,
                            TestResults      = testresults,
                            SourceForm       = collection["sourceform"],
                            GradYear         = gradyear,
                            EduIntent        = eduintent,
                            Recommendations  = recommendations,
                            ClientId         = submissionTokens[1],
                            FormId           = submissionTokens[2],
                            Gender           = gender,
                            CareerId         = submissionTokens[0],
                            SubmissionResult = submissionResult,
                            Data             = data,
                            UtmSource        = utmsource,
                            UtmCampaign      = utmcampaign,
                            UtmContent       = utmcontent,
                            UtmTerm          = utmterm

                            ,
                            City = city
                            ,
                            State = state
                            ,
                            CampusKey = campuskey
                            ,
                            ProgramKey = programkey

                            ,
                            advertise_affsub = advertise_affsub
                            ,
                            advertise_affiliate = advertise_affiliate
                            ,
                            advertise_country = advertise_country
                            ,
                            advertise_countrycode = advertise_countrycode
                            ,
                            advertise_geo = advertise_geo
                            ,
                            advertise_subid = advertise_subid
                            ,
                            advertise_terms = advertise_terms
                            ,
                            advertise_terms_html_kw = advertise_terms_html_kw,

                            PostedString         = strPost,
                            SchoolSearchResultId = schoolsearchresultid
                        });


                        if (campaignid == "13564694")
                        {
                            //Telephony t = new Telephony();
                            //t.SendSMS("+19174340659", "Web lead: " + firstname + " " + lastname);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            AddresseeClient adc            = new AddresseeClient();
            string          emailpartition = AddresseeClient.GetPartitionKeyForEmail(email);
            Addressee       a = adc.GetByPartitionAndRowKey(emailpartition, email);
            if (a == null)
            {
                adc.AddNewItem(new Addressee(email.ToLower())
                {
                    Name = firstname, Email = email.ToLower(),
                });

                UserProfileClient upc     = new UserProfileClient();
                UserProfile       profile = new UserProfile(email.ToLower())
                {
                    Gender       = gender,
                    Salutation   = salutation,
                    FirstName    = firstname,
                    LastName     = lastname,
                    Email        = email,
                    Unsubscribed = false,
                    Zip          = zip,
                    Address1     = address1,
                    City         = city,
                    State        = state,
                    Phone        = phone,
                    CampaignId   = campaignid,
                    GradYear     = gradyear,
                    EduIntent    = eduintent
                };
                profile.PopulateCityAndState();
                profile.SetTestResults(Request);
                profile.SetImportantThings(Request);
                upc.AddNewItem(profile);
            }

            ABTestClient abtc = null;
            abtc = new ABTestClient("Home", Request, Response);
            abtc.CreateGoalConversion("schoolleads", distinctSubmissions.Length);

            Response.Cookies["extendedrecordcomplete"].Value   = "1";
            Response.Cookies["extendedrecordcomplete"].Expires = DateTime.UtcNow.AddDays(90);

            //Only set this cookie for internal
            if (campaignid != "13564694")
            {
                Response.Cookies["ascv"].Value   = conversionValue.ToString();
                Response.Cookies["ascv"].Expires = DateTime.UtcNow.AddDays(90);
            }

            return(RedirectToAction("Index", "SkillTest", new { f = "thanks" }));
        }