private void SetForm(Order odb, FormCollection collection) { odb.FirstName = collection["FirstName"]; odb.LastName = collection["LastName"]; odb.Address = collection["Address"].Replace("\"", "").Trim(); odb.Address2 = collection["Address2"].Replace("\"", "").Trim(); odb.City = collection["City"].Replace("\"", "").Trim(); odb.State = collection["State"].Replace("\"", ""); //state.SelectedValue.ToString(); odb.Zip = collection["Zip"].Replace("\"", "").Trim(); odb.Email = collection["Email"].Replace("\"", "").Trim(); }
public ActionResult Samples(FormCollection collection) { SampleEngine.Order order = new SampleEngine.Order(); string _CCGPID = ConfigurationManager.AppSettings["ccgpid"]; string _DataSourceName = ConfigurationManager.AppSettings["datasource_name"]; string _Source = string.Empty; string bypass = collection["bypass"]; bool match = true; Order odb = new Order(); order.ccgpid = _CCGPID; if (!order.AlreadyRequested(collection["Address"], "", collection["Zip"])) { //check samples if (!order.CampaignExpired()) { //run through standardization Address address = new Address(); address.address1 = collection["Address"].Replace("\"", "").Trim(); address.address2 = ""; // collection["Address2"].Replace("\"", "").Trim(); address.city = collection["City"].Replace("\"", "").Trim(); address.state = collection["State"].Replace("\"", "").Trim(); address.zip = collection["Zip"].Replace("\"", "").Trim(); if (string.IsNullOrEmpty(bypass) || (bypass != "on")) { AddressValidator.AddressValidator adv = new AddressValidator.AddressValidator(); adv.LicenseKey = System.Configuration.ConfigurationManager.AppSettings["LicenseKey"]; adv.Username = System.Configuration.ConfigurationManager.AppSettings["Username"]; adv.Password = System.Configuration.ConfigurationManager.AppSettings["Password"]; adv.address_IN.Address1 = collection["Address"].Replace("\"", "").Trim(); adv.address_IN.Address2 = ""; // collection["Address2"].Replace("\"", "").Trim(); adv.address_IN.City = collection["City"].Replace("\"", "").Trim(); adv.address_IN.State = collection["State"].Replace("\"", "").Trim(); adv.address_IN.Zipcode = collection["Zip"].Replace("\"", "").Trim(); adv.address_IN.CountryCode = "US"; adv.Validate(); if (adv.Match) { if (adv.address_OUT.Count > 0) { match = true; address.address1 = adv.address_OUT[0].Address1; address.address2 = adv.address_OUT[0].Address2; address.city = adv.address_OUT[0].City; address.state = adv.address_OUT[0].State; address.zip = adv.address_OUT[0].Zipcode + "-" + adv.address_OUT[0].Zip4; //address.address_classification = adv.address_OUT[0].AddressClassification == 1 ? 0 : 1; //1 - Residential ; 0 - Commercial address.country = adv.address_OUT[0].CountryCode; //address.address_match = true; } else { match = false; } } else { match = false; } } if (match == false) { // return Redirect(Request.Url + "&match=0"); ViewBag.match = "0"; ViewBag.SampleId = Request.QueryString["s"]; ViewBag.ErrorMessage = "Address Invalid"; SetForm(odb, collection); return View(odb); } else { order.datasource_name = _CCGPID; order.ccgpid = _CCGPID; order.first_name = collection["FirstName"].Replace("\"", "").Trim().ToUpper(); order.middle_initial = ""; order.last_name = collection["LastName"].Replace("\"", "").Trim().ToUpper(); order.address1 = collection["Address"].Replace("\"", "").Trim().ToUpper(); order.city = collection["City"].Replace("\"", "").Trim().ToUpper(); order.state = collection["State"].Replace("\"", ""); //state.SelectedValue.ToString(); order.zip = collection["Zip"].Replace("\"", "").Trim().ToUpper(); order.country = "US"; order.gender = ""; order.contact_language = ""; order.site_language = "en_US"; order.ip_address = Request.UserHostAddress; if (!String.IsNullOrEmpty(Request.QueryString["s"]) && !Request.QueryString["s"].Equals("0")) { order.sampleID = !String.IsNullOrEmpty(Request.QueryString["s"]) ? Convert.ToInt32(Request.QueryString["s"]) : 0; order.ccgsku = Convert.ToInt32(SampleEngine.SampleOffer.GetSampleSku(Convert.ToInt32(Request.QueryString["s"]), _CCGPID)); order.text_val2 = SampleEngine.SampleOffer.GetSampleDescription(Convert.ToInt32(Request.QueryString["s"]), _CCGPID); } order.optin1 = collection["optin"].Equals("false") ? false : true; order.text_val6 = Request.Path; order.UserAgent = Request.UserAgent.ToLower(); order.traffic_source_name = "Minisite"; int orderNumber = order.Save(); if (orderNumber > 0) { //SendEmail(Order.GetTarget(_dealerNo), orderNumber); Response.Redirect("/home/thankyou?onum=" + orderNumber.ToString() + "&lang=" + Request.QueryString["lang"]); } } } else { Response.Redirect("/home/expired?s=" + Request.QueryString["s"] + "&lang=" + Request.QueryString["lang"]); //ViewBag.ErrorMessage = ""; } } else { Response.Redirect("/home/limit?s=" + Request.QueryString["s"] + "&lang=" + Request.QueryString["lang"]); //ViewBag.ErrorMessage = "Sorry! Looks like you've already requested a sample. Unfortunately we can only send you one sample every six months, so keep an eye out and try again soon!"; // BuildLists(); } return View(); }