private OptInLead MergeLeads(List <OptInLead> leads) { //linq not working for first and last here. //only handling situations where there are 2 leads OptInLead lead1 = null; OptInLead lead2 = null; foreach (var lead in leads) { if (lead1 is null) { lead1 = lead; continue; } lead2 = lead; break; } lead1.Firstname = lead1.Firstname ?? lead2?.Firstname; lead1.Lastname = lead1.Lastname ?? lead2?.Lastname; lead1.Address = lead1.Address ?? lead2?.Address; lead1.BirthdayDay = lead1.BirthdayDay ?? lead2?.BirthdayDay; lead1.BirthdayMonth = lead1.BirthdayMonth ?? lead2?.BirthdayMonth; lead1.BirthdayYear = lead1.BirthdayYear ?? lead2?.BirthdayYear; lead1.City = lead1.City ?? lead2?.City; lead1.State = lead1.State ?? lead2?.State; lead1.Zip = lead1.Zip ?? lead2?.Zip; return(lead1); }
public Guid?CreatePrecisionSampleUser(RouterContact routerContact) { GloshareDbContext db = new GloshareDbContext(); var existingPS = db.RouterContactPrecisionSamples.FirstOrDefault(p => p.RouterContactId == routerContact.RouterContactId); if (existingPS != null) { return(existingPS.UserGuid); } var ps = new PrecisionSample(); var leads = db.OptInLeads.Where(o => o.EmailAddress == routerContact.Email).ToList(); FormUrlEncodedContent content = null; if (leads.Any()) { OptInLead lead = leads.First(); if (leads.Count == 2) { lead = MergeLeads(leads); } content = ps.CreatePostContent(routerContact, lead); } //use the mobile lead over the opt in lead if both emails exist var mobileleads = db.MobilelLeads.Where(m => m.EmailAddress == routerContact.Email); if (mobileleads.Any()) { content = ps.CreatePostContent(routerContact, mobileleads.First()); } bool error = false; string userguid = ps.CreateUser(routerContact, content, out error); if (error) { OnProgress(new ProgressEventArgs(new string('=', 50))); OnProgress(new ProgressEventArgs($"Failed Creating Precision Sample User:{routerContact.Email}{Environment.NewLine}")); //contains raw message on fail OnProgress(new ProgressEventArgs($"{userguid}")); return(null); } RouterContactPrecisionSample rcps = new RouterContactPrecisionSample { UserGuid = Guid.Parse(userguid), RouterContactId = routerContact.RouterContactId }; db.RouterContactPrecisionSamples.Add(rcps); db.SaveChanges(); return(Guid.Parse(userguid)); }
private string GetDOB(OptInLead lead) { if (lead.BirthdayDay.HasValue && lead.BirthdayDay > 0 && lead.BirthdayMonth.HasValue && lead.BirthdayMonth > 0 && lead.BirthdayYear.HasValue && lead.BirthdayYear.HasValue) { return($"{lead.BirthdayMonth}/{lead.BirthdayDay}/{lead.BirthdayYear}"); } return(null); }
public MinimumInfoExistsResult CheckIfMinimumInfoExistsForEmail(string emailAddress) { var db = new GloshareDbContext(); var oilLeads = db.OptInLeads.Where(o => o.EmailAddress == emailAddress).ToList(); if (!oilLeads.Any()) { return(new MinimumInfoExistsResult() { EmailNotFound = true }); } OptInLead lead = oilLeads.First(); if (oilLeads.Count > 1) { lead = MergeLeads(oilLeads); } MinimumInfoExistsResult minimumInfoExistsResult = new MinimumInfoExistsResult() { NeedsDOB = true, NeedsGender = string.IsNullOrWhiteSpace(lead.Gender), NeedsZip = string.IsNullOrWhiteSpace(lead.Zip) }; string dobString = $"{lead.BirthdayMonth}/{lead.BirthdayDay}/{lead.BirthdayYear}"; DateTime dob; if (DateTime.TryParse(dobString, out dob)) { minimumInfoExistsResult.NeedsDOB = false; } minimumInfoExistsResult.HasMinimumInfo = !minimumInfoExistsResult.NeedsDOB && !minimumInfoExistsResult.NeedsZip && !minimumInfoExistsResult.NeedsGender; if (minimumInfoExistsResult.HasMinimumInfo) { var routerContact = db.RouterContacts.FirstOrDefault(r => r.Email == emailAddress); if (routerContact != null) { minimumInfoExistsResult.HasRounterContact = true; minimumInfoExistsResult.RouterContactUniqueId = routerContact.UniqueId; } } return(minimumInfoExistsResult); }
private string GetGender(OptInLead lead) { if (string.IsNullOrWhiteSpace(lead.Gender)) { return(null); } if (lead.Gender.Length == 1) { return(lead.Gender); } return(lead.Gender.Substring(0, 1)); }
private string GetEthnicity(OptInLead lead) { if (string.IsNullOrWhiteSpace(lead.Ethnicity)) { return(null); } if (lead.Ethnicity == "Caucasian") { return("1"); } if (lead.Ethnicity == "African American") { return("2"); } if (lead.Ethnicity == "Hispanic") { return("3"); } if (lead.Ethnicity == "Asian" || lead.Ethnicity == "Indian") { return("5"); } if (lead.Ethnicity == "Native American") { return("4"); } if (lead.Ethnicity == "Middle Eastern") { return("12"); } if (lead.Ethnicity == "Other") { return("15"); } return("15"); }
public FormUrlEncodedContent CreatePostContent(RouterContact routerContact, OptInLead lead) { var content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("RID", "20690"), new KeyValuePair <string, string>("TxId", ""), new KeyValuePair <string, string>("ExtMemberId", routerContact.RouterContactId.ToString()), new KeyValuePair <string, string>("Country", lead.CountryId ?? "US"), new KeyValuePair <string, string>("State", lead.State), new KeyValuePair <string, string>("FirstName", lead.Firstname), new KeyValuePair <string, string>("LastName", lead.Lastname), new KeyValuePair <string, string>("EmailAddress", lead.EmailAddress), new KeyValuePair <string, string>("Zip", lead.Zip), new KeyValuePair <string, string>("Gender", GetGender(lead)), new KeyValuePair <string, string>("Dob", GetDOB(lead)), new KeyValuePair <string, string>("Address1", lead.Address), new KeyValuePair <string, string>("Address2", lead.Address2), new KeyValuePair <string, string>("City", lead.City), new KeyValuePair <string, string>("Ethnicity", GetEthnicity(lead)), }); return(content); }
public MobileSignupResponse SignUpUser(string email, string ipAddress) { var db = new GloshareContext(); if (string.IsNullOrWhiteSpace(email)) { return(new MobileSignupResponse() { Message = "Email is blank." }); } try { var xv = new XVerifyManager(); if (xv.GetEmailVerification(email)) { string countryId = GetCountryId(ipAddress); var response = new MobileSignupResponse(); response.ValidEmail = true; MobilelLead existingLead = db.MobilelLeads.FirstOrDefault(m => m.EmailAddress.ToLower() == email); if (existingLead == null) { email = email.Trim().ToLower(); existingLead = new MobilelLead() { EmailAddress = email, Ip = ipAddress, CountryId = countryId }; db.MobilelLeads.Add(existingLead); db.SaveChanges(); var oils = db.OptInLeads.Where(o => o.EmailAddress == email); if (!oils.Any()) { var oil = new OptInLead(); oil.EmailAddress = email; oil.Ip = ipAddress; oil.OfferId = "51011"; db.OptInLeads.Add(oil); db.SaveChanges(); } } return(new MobileSignupResponse() { UserId = existingLead.UserId, IsRegistered = existingLead.IsRegistered, DisplayName = string.IsNullOrWhiteSpace(existingLead.Firstname) ? null : $"{existingLead.Firstname} {existingLead.Lastname}", ValidEmail = true, Message = "Success", DashUrl = $"{ConfigurationManager.AppSettings["BaseWebUrl"]}dash?ug={existingLead.UserId}", RegisterUrl = $"{ConfigurationManager.AppSettings["BaseWebUrl"]}register?ug={existingLead.UserId}", DailySurveysUrl = $"{ConfigurationManager.AppSettings["BaseWebUrl"]}mysurveys?mu={existingLead.UserId}", EarningsUrl = $"{ConfigurationManager.AppSettings["BaseWebUrl"]}earnings?ug={existingLead.UserId}" }); } return(new MobileSignupResponse() { ValidEmail = false, Message = "Email Invalid." }); } catch (Exception e) { return(new MobileSignupResponse() { Message = $"Error: {e.Message}" }); } }